See this scene in the group today:
See here, let's learn this RM directive
RM command to delete one or more files or directories in a directory, or to delete all files and subdirectories of a directory and its subordinates. For linked files, only the entire linked file is deleted, and the original file remains unchanged.
Note : Use the RM command with extreme caution. Because once a file is deleted, it can no longer be recovered. So, before deleting a file, it's a good idea to look at the contents of the file and determine if you really want to delete it. The RM command can be used with the-I option, which is particularly useful when deleting multiple files using the file extension name character. With this option, you will be asked to determine whether you want to delete it. In this case, you must enter Y and press ENTER to delete the file. If you press the ENTER key or other characters only, the file is not deleted.
Grammar:
RM (option) (parameter)
Options
-D: Delete the hard connection data of the directory you want to delete to 0, delete the directory;-F: Forcibly delete the file or directory;-I: Ask the user before deleting an existing file or directory;-R or-R: recursively processing all files in the specified directory with subdirectories ;--preserve-root: Do not recursively operate the root directory;-V: Displays detailed execution of instructions.
Parameters
File: Specifies the list of files to be deleted, or if the parameter contains a directory, you must add -r
or -R
select an option.
Instance
Interactively delete files in the current directory Test and example
Rm-i Test exampleremove Test N (Do not delete file test) Remove example y (delete file example)
Delete all files and subdirectories in the current directory except for hidden files
# Rm-r *
That is: RM-RF/* (is the mandatory deletion of the root directory and all the subdocuments)
Workaround (To resolve the set of methods for accidental deletion):
In order to avoid mistakenly deleting the root directory, or important files, the following methods are collated:
1, SAFE-RM
SAFE-RM is an open source software used to replace the less secure RM, you can configure the path blacklist in/etc/safe-rm.conf, define which cannot be deleted by SAFE-RM.
You can rename the Safe-rm to RM and place it in the $PATH before the original RM program. The use of full path/bin/rm in some scripts is not affected by this.
$ rm-rf/etc/safe-rm:skipping/etc/
Official address: Http://freecode.com/projects/safe-rm,ubuntu can be installed directly apt-get, CentOS to download the source code installation.
2, the establishment of recycling station mechanism
It does not actually perform the delete operation, but instead moves the file to a specific directory, can set the time to clear the Recycle Bin, or in the Recycle Bin when the size of the file reaches a certain capacity (or when the decision is made by The times) to make room for the deletion.
You can either write a shell script to replace the RM command, or use the MV command to move the file to the Recycle Bin when you need to delete the file.
1) Create a new directory under the/home/username/directory, named:. Trash
2) in the/home/username/tools/directory, create a new shell file named: remove.sh
Trash_dir= "/home/username/.trash" for I in $*, do stamp= ' date +%s ' filename= ' basename $i ' mv $i $TRASH _dir/$fileName. $STAMP done
3) Modify ~/.BASHRC, add a line
Alias rm= "Sh/home/username/tools/remove.sh"
Replace the RM command with our self-built remove.sh
4) Set the crontab and empty the bins regularly, such as:
0 0 * * * rm-rf/home/username/.trash/*
Empty the trash bin at 0 o ' Day
5) source ~/.BASHRC make the substitution take effect immediately
3, pay attention to the use of RM-RF variables in the script
In the script try not to use RM-RF $FOO/, please use RM-RF $FOO; also delete try not to write relative paths, do not take variables.
4. root file system settings read-only mount
Noauto,ro
5. Various backup
You can remotely back up important data, using Dump's incremental backup mechanism, LVM snapshots, snapshots in virtualized environments, RAID5, and so on.
Appendix: How do I prevent accidental rm-rf/*?
Follow the blog, progress a little bit every day! hehe ~ ~ ~
Linux (RM instructions) and accidental deletion resolution