How to Create Directories on Your Raspberry Pi - dummies

How to Create Directories on Your Raspberry Pi

By Sean McManus, Mike Cook

You can create directories on your Raspberry Pi. As you may know from other computers you’ve used, it’s a lot easier to manage the files on your computer if they’re organized into directories (or folders). You can easily create a directory in your home directory using the command mkdir:

mkdir work

To save time, use one command to create several directories, like this:

pi@raspberrypi ~ $ mkdir work college games

pi@raspberrypi ~ $ ls

Downloads python_games work college Music Desktop Pictures Documents games Public Templates Videos

You might see additional files here, especially if you followed the earlier examples to make some text files, but the important thing is that one command made three new directories for you.

The mkdir command’s ability to make several directories at the same time isn’t unusual: Many other commands can also take several arguments and process them in order. You can see the listing of two different directories like this, for example:

ls ~ /boot

The mkdir command doesn’t give you a lot of insight into what it’s doing by default, but you can add the -v option (short for verbose), which gives you a running commentary as each directory is created. You can see what that looks like in the next code snippet.

If you want to make some directories with subdirectories inside them, it would be a nuisance to have to create a directory, go inside it, create another directory, go inside that, and so on. Instead, use the -p option, like this:

pi@raspberrypi ~ $ mkdir –vp work/writing/books

mkdir : created directory 'work'

mkdir : created directory 'work/writing'

mkdir : created directory 'work/writing/books'

The command keeps you informed of any changes it makes, but if the work directory already exists, you won’t see the first line of output shown here.