RM Delete File command
1 , command format
RM [Options] File ...
2. Command function
RM Command, delete File command, is a common command under the Linux system, the function of the command is to delete a file or a whole directory or a part of the directory, it can also be a directory and all of its files and subdirectories are deleted. For linked files, only the link is deleted and the original file remains unchanged.
RM is a dangerous command, especially when used, especially for novices, or the entire system will be destroyed in this command (e.g., RM *-RF or RM-RF/) in the/(root directory). So, before we execute RM, it's a good idea to check in which directory, exactly what to delete, and keep a high level of sanity in the operation.
3 , command parameters
-F: Force Delete, delete without asking the administrator, delete the nonexistent file does not prompt
-I: Interactive Delete, ask the administrator for each deletion of a file
-R,-R,--recursive: recursively delete directories and content, typically used to delete directories
-V,--verbose Delete message when deleting a file
--HELP Display this help message and exit
--version output version information and exit
4 , common examples
Example 1 : Delete the passwd file under the file/TMP, the system will first ask whether to delete
Command: RM/TMP/PASSWD
[Email protected] ~]# ls/tmp/passwd yum.log[[email protected] ~]# rm/tmp/passwd rm:remove regular file '/tmp/passwd '? Y//y means confirm delete, n is not deleted [[email protected] ~]# Ls/tmp/[[email protected] ~]#
Hint: The system default to the RM name generated a command alias, can be viewed with the alias command, function: Delete files or directories to ask the administrator, if you do not want to ask, use Rm-f or \RM;\RM is the command itself instead of the command alias
Example 2: Delete all files under/tmp
[Email protected] ~]# mkdir/tmp/test{1,2,3,4,5}[[email protected] ~]# ls/tmp/test1 test2 test3 test4 test5 yum.log[[ Email protected] ~]# cp/tmp/yum.log./[[email protected] ~]# rm-r/tmp/* rm:remove directory '/tmp/test1 '? Yrm:remove directory '/tmp/test2 '? Yrm:remove directory '/tmp/test3 '? Yrm:remove directory '/tmp/test4 '? Yrm:remove directory '/tmp/test5 '? Yrm:remove regular empty file '/tmp/yum.log '? Y[[email protected] ~]#
Example 3: Deleting a *.log file from/tmp
Command: Rm-f/tmp/*.log
[[email protected] ~]# ls/tmp/yum1.log yum.log[[email protected] ~]# rm-f/tmp/*.log delete file suffix. log [[email protected] ~]# Ls/tmp/[[email protected] ~]#
Example 4: The system does not ask when deleting files/tmp/fstab files
Command: Rm-f/tmp/fstab|\rm/tmp/fstab
[Email protected] ~]# ls/tmp/fstab[[email protected] ~]# rm-f/tmp/fstab [[email protected] ~]# Ls/tmp[[email protecte D] ~]#
Common Small Commands
pwd show the path to your directory
command Format pwd [-l|-p]
basename : Fetch path base name
command format: basename DIRECTORY
dirname : Fetch path directory name
command format: dirname DIRECTORY
Common examples
Show current Path
command: pwd
[[Email protected]~]# pwd/root[[email protected]~] #取/etc/sysconfig/network-scripts/ifcfg-eth0 's base name command: basename/etc/ Sysconfig/network-scripts/ifcfg-eth0[[email protected]~]# Basename/etc/sysconfig/network-scripts/ifcfg-eth0 Ifcfg-eth0[[email protected]~] #取 The path name of the/etc/sysconfig/network-scripts/ifcfg-eth0 [email protected]~]# dirname/etc/ Sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts[[email protected]~]#
basename and the dirname commonly used in script programming
This article is from "Linux rookie" blog, please be sure to keep this source http://geekb0y.blog.51cto.com/10743719/1881332
One day a linux base command to delete a file or directory command RM