Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

W W W . L I N U X D O T . O R G

Newbie's Linux Manual
Command Tutorial #3: mkdir & rmdir
by Laurence Hunter
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Making and Removing Directories

Learn by doing is the nature of this manual, and in keeping with that belief, here's a tutorial to teach you the mkdir and rmdir commands, to make and remove directories.

- 1 -

Rather than entering a tedious:

cd     (Only required if you're not in your home directory.)
mkdir a
mkdir a/sub
mkdir a/sub/subsub

...simply enter:

cd; mkdir a a/sub a/sub/subsub

Note:

Here you've just been introduced to a nice trick - using the semi-colon (;) to enter multiple commands in one go. This will work with anything you can think of.

- 2 -

To check that everything is, as it should be, enter:

tree a

...to display the following:


a `-- sub `-- subsub 2 directories, 0 files
Note:
If tree doesn't work, you don't have it installed.
- 3 -

Now that the three directories have been created, it's time to destroy them!

Enter:

rmdir a

Some Things You Can't Do

To prevent accidents, rmdir will refuse to remove directories that contains files and/or other directories. Which is why you received the error message:

rmdir: a: Directory not empty

This will also prevent you removing a parent directory, since by its very name, it has to contain your current working directory. Logic also dictates that you can't remove your current directory since this would involve you being lost in limbo'!

- 4 -

The rmdir has a handly little option, called -p. It's purpose is to ask the shell to not only remove a directory, but also all of its parent directories - so long as each parent is empty. Don't worry about accidentally deleting something you shouldn't have, the design of the Unix filesystem and its simple rules I mentioned above, prevent disaster from occuring. The creators of Unix were nothing if not geniuses.

Enter:

rmdir -p a/sub

...oh dear, still an annoying error message:

rmdir: a/sub: Directory not empty

- 5 -

Now press the up cursor key to bring back up the last command, but this time add /subsub before pressing the Return key, like so:

rmdir -p a/sub/subsub

Bingo, all three directories have been removed!

[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Homepage | The Last 5 Days | The Daily Linux News | The Linux Bits | Newbie's Linux Manual
The Best Linux Sites | Linux Book Reviews | A Windows Vendetta?
Diary of a Linux Newbie | Diary of an Open Source Newbie
The Linux Forum | Just For Fun
Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy!
© MM Linuxdot.org | Webmaster | Manual's Copyright Terms