Книга: 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.
- Printing the Contents of a File with cat
- Changing Directories with cd
- Changing File Access Permissions with chmod
- Copying Files with cp
- Printing Disk Use with du
- Finding Files by Searching with find
- Searches for a String in Input with grep
- Paging Through Output with less
- Creating Links Between Files with ln
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Reading Manual Pages with man
- Making Directories with mkdir
- Moving Files with mv
- Listing Processes with ps
- Deleting Files and Directories with rm
- Printing the Last Lines of a File with tail
- Printing Resource Usage with top
- Printing the Location of a Command with which
- Basic Commands
- Finding Files from an Index with locate
- Moving Files with mv
- Printing the Location of a Command with which
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 16. Commercial products based on Linux, iptables and netfilter