# This script demonstrates the ‹rm› command, which primarily removes # (unlinks) files. It can, however, also remove directories and it # can remove entire directory trees recursively. First some simple # cases: set -x touch file # recall that this creates an empty file ls file # does it exist? rm file # remove it ls file # check again rm file # this prints an error, since ‹file› no longer exists rm -f file # not an error -- this just ensures the file is not there mkdir dir rm dir # this is an error rm -d dir # this works (but is non-standard, even if common) touch file rm -d file # this also works # Now let's try something more complicated (and dangerous!): mkdir -p dir/subdir/stuff touch dir/subdir/stuff/file touch dir/file rm -d dir # fails rmdir dir # also fails rm -df dir # still fails rm -r dir # finally! r is for recursive # For extra power (and danger), you could say ‹rm -rf›. Always # remember that ‹rm› does not ask before deleting all your data. If # you are unsure about the command, use ‹rm -i›, like this: touch some_file rm -i some_file # That's about as much as we need to know about removing files and # directories using user-level commands. Let's have a look at # ‹unlink.c› now.