Книга: Fedora™ Unleashed, 2008 edition

Deleting Files and Directories with rm

Deleting Files and Directories with rm

The rm command has only one parameter of interest: --preserve-root. By now, you should know that issuing rm -rf / as root will destroy your Linux installation because -r means recursive and -f means force (do not prompt for confirmation before deleting). It is possible for a clumsy person to issue this command by accident — not by typing the command on purpose, but by putting a space in the wrong place. For example:

$ rm -rf /home/paul

That command deletes the home directory of the user paul. This is not an uncommon command; after you have removed a user and backed up her data, you will probably want to issue something similar. However, if you add an accidental space between the / and the h in home, you get this:

$ rm -rf / home/paul

This time the command means "delete everything recursively from / and then delete home/paul" — quite a different result! You can stop this from happening by using the --preserve-root parameter, which stops you from catastrophe with this message:

rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe.

Of course, no one wants to keep typing --preserve-root each time he runs rm, so you should add this line to the .bashrc file in your home directory:

alias rm='rm --preserve-root'

That alias automatically adds --preserve-root to all calls to rm in future bash sessions.

Оглавление книги


Генерация: 1.018. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз