5.L: Controlling Access to Files and Directories | 5: Managing Files and Directories | 5.J: Removing Files |
The problem with the "remove" command is that once a file is removed, it is gone completely; even if you really did not want to remove it. Inadvertently removing a directory full of wanted files could be even more of a disaster. And so Unix, tries to protect you somewhat from yourself.
In order to remove a directory, you must first empty it of all files,
and then "remove the directory" with the special rmdir
command:
> cd ~/development/prog
> rm -i bu/*
> rmdir bu
> ls
Note, you already have a copy of development/prog in the
backupdev directory, so don't be afraid to try this. You will be
asked to confirm your wishes to remove each file, at which point a reply of
y
is appropriate. When every last file is gone (and this
includes dotfiles if you have any other than . and ..), you can remove the
directory. Finally, do a ls
to check that the directory is
gone.
Although it chills our heart to tell you this, you can also remove all the files in a directory and the directory itself, just by using the recursive option with the remove command:
> rm -r bu
The problem is this is so quick and final, and if you make a typing
mistake (like putting in a *
), can be so devasting. If this
is too elegant to resist, at least use the interactive option:
> rm -ir bu