Making Directories

We’ve talked about moving around in directories and what they’re called, but we haven’t talked about ma king directories yet. So let’s do that. To make a directory, the command is mkdir. The command looks like:

Alpha:~ computerlamp$ mkdir deathstar

Now that we made it, if we do a ls we’ll see it

Alpha:~ computerlamp$ ls
deathstar

You can look in it by doing

Alpha:~ computerlamp$ ls deathstar

And since it’s empty, then that command will show nothing. We can remove the directory with the command rmdir. The command looks like:

Alpha:~ computerlamp$ rmdir deathstar

What happens if I try to remove a directory that doesn’t exist?

Alpha:~ computerlamp$ rmdir notreal
rmdir: notreal: No such file or directory

The command rmdir only works if the directory is empty. If it isn’t, this happens:

Alpha:~ computerlamp$ rmdir deathstar
rmdir: deathstar/: Directory not empty

So now we know how to create directories. We can also change directory into the new directory with:

Alpha:~ computerlamp$ cd deathstar

And cd back to where we started with:

Alpha:~ computerlamp$ cd ..

Another trick to return to the directory we started with is:

Alpha:~ computerlamp$ cd -

You can think of this as ‘change directory back to where I started with, no matter how weird my new directory is.’

Leave a Reply

Your email address will not be published. Required fields are marked *