rm
rm command to delete a directory of one or more files or directories can also be a directory and its subdirectories subordinate all files are deleted. For the linked file, just delete the entire link file, and the original file remains unchanged
Note : Use the rm command to be extra careful. Because once a file is deleted, it can not recover it. So, before you delete a file, it is best to look at the contents of the file, determine whether you really want to delete. rm command can be particularly useful when deleting multiple file names with characters -i option, which use the file extensions. With this option, you will be asked individually to determine whether you want to delete. In this case, you must enter y and press Enter to delete the file. If you only press the Enter key or other characters, files are not deleted.
format
rm [options] [file ...]
Parameter options
parameter | Remark |
---|---|
-d | Hard-wired directly to delete the directory data to be deleted to 0, delete the directory |
-f | Force delete files or directories; |
-i | First ask the user before you delete an existing file or directory; |
-r or -R | Recursive processing, all files and subdirectories in the specified directory treated together; |
--preserve-root | Recursion is not the root directory; |
-v | Show the detailed process of executing instructions. |
Examples
Delete files file, the system will be asked whether to delete
Command: RM file name
[root@VM_0_9_centos ~]# rm testFile1 rm: remove regular empty file testFile1?. y
Forcibly remove the file, the system will not prompt
Command: RM -f log1.log
[root@VM_0_9_centos ~]# touch log1.log [root@VM_0_9_centos ~]# rm -f log1.log
Delete any .log files; asking each confirmation before deleting
Command: RM -i * .log
[root@VM_0_9_centos ~]# touch log1.log [root@VM_0_9_centos ~]# touch log2.log [root@VM_0_9_centos ~]# rm -i *.log rm: remove regular empty file log1.log?. y rm: remove regular empty file log2.log?. y
The test directory and all subdirectories deleted files
Command: RM -r the Test
[root@VM_0_9_centos ~]# mkdir test [root@VM_0_9_centos ~]# cd test [root@VM_0_9_centos test]# touch file1 [root@VM_0_9_centos test]# touch file2 [root@VM_0_9_centos test]# touch file3 [root@VM_0_9_centos test]# rm -r ../test rm: descend into directory ./test?. y rm: remove regular empty file ./test/file3?. y rm: remove regular empty file ./test/file2?. y rm: remove regular empty file ./test/file1?. y rm: remove directory ./test?. y
rm -rf test2 test2 command will subdirectories and delete all files in subdirectories, and not eleven confirmed
Command: RM -rf test2
同上,只是没有确认删除提示
Wildcard matching delete, delete the file name of the file begins with wuzhazha
Command: RM wuzhazha
[root@VM_0_9_centos ~]# touch wuzhazha.txt [root@VM_0_9_centos ~]# touch wuzhazha1.txt [root@VM_0_9_centos ~]# touch wuzhazha2.txt [root@VM_0_9_centos ~]# rm wuzhazha* rm: remove regular empty file wuzhazha1.txt?. y rm: remove regular empty file wuzhazha2.txt?. y rm: remove regular empty file wuzhazha.txt?. y