17.5 Copying, Moving and Renaming Files and Directories 269
[billy@localhost billy]$ rm -i piglet.txt
rm: remove ’piglet.txt’?
You can also delete files using the wildcard *, but be careful, because you can easily delete files you
didn’t intend to throw away.
To remove a file using a wildcard, you would type:
rm pig*
You can also remove more than one file in one command, as in:
rm piglet.txt sneakers.txt
Options for removing files – and directories – include:
-i – interactive. Prompts you to confirm the deletion. This is good.
-f – force. Overrides interactive mode and removes the file(s) without prompting. This might
not be good, unless you know exactly what you’re doing.
-v – verbose. Shows a listing of files as they’re being removed.
-r – recursive. When removing directories, will remove all of the files and the subdirectories
of the specified directory. This can also get rid of an empty directory.
To remove directories with rm, you must specify the -r option.
For example, if you want to recursively remove the directory tigger you would type:
rm -r tigger
And if you want to combine options, such as forcing a recursive deletion, you can type:
rm -rf tigger
Tip: Be careful! rm is a powerful command, and can delete your entire system! If you’re
root and you type the simple command rm -rf / you’re sunk – like a snake eating its
tail, the command will recursively remove everything on your system.
The safer alternative to using rm for removing directories is the rmdir command. With this com-
mand, you won’t be allowed to use recursive deletions, so a directory which has files in it won’tbe
deleted.
Read the rmdir man page by typing man rmdir to find out more about the command.
Comments to this Manuals