语法
rm [OPTION]... FILE...
rm介绍
linux中删除文件和目录的命令: rm命令。rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除。对于链接文件,只是删除了链接,原有文件均保持不变。
选项
-f, --force 忽略不存在的文件,从不给出提示。即删除文件的时候,不给出确认是否删除的选项。
-i, --interactive 进行交互式删除,即删除目录的时候同时删除其后代文件或目录。
-r, -R, --recursive 指示rm将参数中列出的全部目录和子目录均递归地删除。
-v, --verbose 详细显示进行的步骤
--help 显示此帮助信息并退出
--version 输出版本信息并退出
案例一:
[root@localhost test]# rm -rf test2 #命令会将 test2 子目录及子目录中所有档案删除,并且不用一一确认
[root@localhost test]# ll
总计 16drwxr-xr-x 7 root root 4096 10-25 18:07 scf
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
drwxr-xr-x 2 root root 4096 10-25 17:56 test4
drwxr-xr-x 3 root root 4096 10-25 17:56 test5
案例二:直接删除,不给出删除提示
[root@iZ25sngm7hfZ wyq]# rm s
rm: cannot remove `s': No such file or directory
[root@iZ25sngm7hfZ wyq]# rm -f s
案例三:-i 选项使用
[root@iZ25sngm7hfZ ~]# rm -i s #
rm: remove regular file `s'? y
[root@iZ25sngm7hfZ ~]# rm -i sr.txt
rm: remove regular file `sr.txt'? n
[root@iZ25sngm7hfZ ~]# rm -f sr.txt
案例四:显示帮助文件
[root@iZ25ja2kaemZ ~]# rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).
-f, --force ignore nonexistent files, never prompt,删除文件时不再提示用户是否删除。
-i prompt before every removal,每次删除文件,都进行提示。
-I prompt once before removing more than three files, or
when removing recursively. Less intrusive than -i,
while still giving protection against most mistakes
--interactive[=WHEN] prompt according to WHEN: never, once (-I), or
always (-i). Without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root do not treat `/' specially
--preserve-root do not remove `/' (default)
-r, -R, --recursive remove directories and their contents recursively,递归删除目录及其后代目录或文件。删除一个目录中的一个或多个文件或目录,如果没有使用- r选项,则rm不会删除目录。
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit
By default, rm does not remove directories. Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.
To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
rm -- -foo
rm ./-foo
Note that if you use rm to remove a file, it is usually possible to recover
the contents of that file. If you want more assurance that the contents are
truly unrecoverable, consider using shred.
Report rm bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'rm invocation'