rm

删除文件(删除/取消链接)

语法

  rm [options]... file...

选项




   -f, --force
       强制删除,忽略不存在的文件,永远不会提示
   -i
       每次删除前提示 
   -I
       在删除三个以上文件或递归删除之前提示一次
   --interactive[=WHEN]
       根据指定的WHEN 进行确认提示:never,once (-I)
       或者always (-i)。如果此参数不加WHEN 则总是提示
   --one-file-system
       递归删除一个层级时,跳过所有不符合命令行参
       数的文件系统上的文件 
   --no-preserve-root
       不特殊对待"/"
   --preserve-root
       不允许删除"/"(默认)
   -r, -R, --recursive
        递归删除目录及其内容
   -v, --verbose
       详细显示进行的步骤
   --help
       显示此帮助信息并退出
   --version
        显示版本信息并退出要删除文件,您必须对该文件及其存储位置具有写入权限。文件的OWNER不需要rw权限才能使用它。

默认情况下,rm不会删除目录。使用–recursive(-r或-R)选项也可以删除每个列出的目录及其所有内容。

请注意,如果使用rm删除文件,通常可以恢复该文件的内容。如果您想要更加确保内容真正无法恢复,请考虑使用shred。

扩展变量

如果要扩展变量,请始终在文件名周围加上引号,以防它包含空格:

rm -- "$filename"

rm命令接受 – 选项, 这将导致它从该点向前停止处理标志选项.
如果没有这个,恰好包含“ -rf ”之类的文件名变量将被解释为命令的一部分.

使用 – 还允许删除以破折号开头的文件名 -.

rm -- -some_file

或者使用绝对或相对路径引用.

rm /home/user/-some_file
rm ./-some_file

实例

删除文件需要确认

rm test.txt

强制删除文件不确认

rm -f test.txt

强制删除当前的test目录,并显示删除的详细过程

rm -rfv test

递归强制删除非空文件夹

rm -rf test

rm 命令实例:

linux命令:rmdir / backup / all all / backup / rmdir rmdir / backup / allrootopen.com
linux命令:rmdir / backup / all all / backup / rmdir rmdir / backup / allrootopen.com
2018-09-11 09:55:30

linux命令:rm -- --myfile --myfile -- rm rm -- --myfilerootopen.com
linux命令:rm -- --myfile --myfile -- rm rm -- --myfilerootopen.com
2018-01-24 20:27:48

linux命令:rm -rf `find . -type d -name .svn` .svn` -name d -type . `find -rf rm rm -rf `find . -type d -name .svn`rootopen.com
linux命令:rm -rf `find . -type d -name .svn` .svn` -name d -type . `find -rf rm rm -rf `find . -type d -name .svn`rootopen.com
2018-03-08 08:30:48

linux命令:rm ./-filename ./-filename rm rm ./-filenamerootopen.com
linux命令:rm ./-filename ./-filename rm rm ./-filenamerootopen.com
2018-01-11 06:50:48

linux命令:rm -rf `ls | head -5000` -5000` head | `ls -rf rm rm -rf `ls | head -5000`rootopen.com
linux命令:rm -rf `ls | head -5000` -5000` head | `ls -rf rm rm -rf `ls | head -5000`rootopen.com
2018-04-13 17:32:48

linux命令:rm file{1..10} file{1..10} rm rm file{1..10}rootopen.com
linux命令:rm file{1..10} file{1..10} rm rm file{1..10}rootopen.com
2018-03-12 07:20:48

linux命令:rm -rf `find . -type d -name .svn` .svn` -name d -type . `find -rf rm rm -rf `find . -type d -name .svn`rootopen.com
linux命令:rm -rf `find . -type d -name .svn` .svn` -name d -type . `find -rf rm rm -rf `find . -type d -name .svn`rootopen.com
2018-03-07 21:36:48

linux命令:rm -rf ~/.local/share/Trash/files/* ~/.local/share/Trash/files/* -rf rm rm -rf ~/.local/share/Trash/files/*rootopen.com
linux命令:rm -rf ~/.local/share/Trash/files/* ~/.local/share/Trash/files/* -rf rm rm -rf ~/.local/share/Trash/files/*rootopen.com
2018-02-12 05:50:48

linux命令:rm -rf `find ./ -iname *.svn*` *.svn*` -iname ./ `find -rf rm rm -rf `find ./ -iname *.svn*`rootopen.com
linux命令:rm -rf `find ./ -iname *.svn*` *.svn*` -iname ./ `find -rf rm rm -rf `find ./ -iname *.svn*`rootopen.com
2018-01-17 16:33:48

linux命令:rm -r .??* .??* -r rm rm -r .??*rootopen.com
linux命令:rm -r .??* .??* -r rm rm -r .??*rootopen.com
2018-02-21 18:49:48

linux命令:rm ~/.mozilla/firefox/<profile_dir>/.parentlock ~/.mozilla/firefox/<profile_dir>/.parentlock rm rm ~/.mozilla/firefox/<profile_dir>/.parentlockrootopen.com
linux命令:rm ~/.mozilla/firefox/<profile_dir>/.parentlock ~/.mozilla/firefox/<profile_dir>/.parentlock rm rm ~/.mozilla/firefox/<profile_dir>/.parentlockrootopen.com
2018-01-14 00:35:48

linux命令:rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache' rmcache='rm_cache' alias }; $HOME/.mozilla/firefox/<profile>/Cache/* -f rm { rm_cache() rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache'rootopen.com
linux命令:rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache' rmcache='rm_cache' alias }; $HOME/.mozilla/firefox/<profile>/Cache/* -f rm { rm_cache() rm_cache() { rm -f $HOME/.mozilla/firefox/<profile>/Cache/* }; alias rmcache='rm_cache'rootopen.com
2018-04-23 10:25:48

linux命令:rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7` +7` -mtime 1 -mindepth 1 -maxdepth `find -rf rm rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7`rootopen.com
linux命令:rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7` +7` -mtime 1 -mindepth 1 -maxdepth `find -rf rm rm -rf `find -maxdepth 1 -mindepth 1 -mtime +7`rootopen.com
2018-04-08 23:53:48

linux命令:rm strangedirs -rf -rf strangedirs rm rm strangedirs -rfrootopen.com
linux命令:rm strangedirs -rf -rf strangedirs rm rm strangedirs -rfrootopen.com
2018-01-24 03:15:48

linux命令:rm -d **/*(/^F) **/*(/^F) -d rm rm -d **/*(/^F)rootopen.com
linux命令:rm -d **/*(/^F) **/*(/^F) -d rm rm -d **/*(/^F)rootopen.com
2018-02-05 00:22:48

linux命令:rmdir **/*(/^F) **/*(/^F) rmdir rmdir **/*(/^F)rootopen.com
linux命令:rmdir **/*(/^F) **/*(/^F) rmdir rmdir **/*(/^F)rootopen.com
2018-03-11 12:02:48

linux命令:rm -vf /backup/directory/**/FILENAME_*(m+15) /backup/directory/**/FILENAME_*(m+15) -vf rm rm -vf /backup/directory/**/FILENAME_*(m+15)rootopen.com
linux命令:rm -vf /backup/directory/**/FILENAME_*(m+15) /backup/directory/**/FILENAME_*(m+15) -vf rm rm -vf /backup/directory/**/FILENAME_*(m+15)rootopen.com
2018-01-23 11:35:48

linux命令:rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]* c[b-zA-Z0-9]* [a-bd-zA-Z0-9]* -rf rm rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]*rootopen.com
linux命令:rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]* c[b-zA-Z0-9]* [a-bd-zA-Z0-9]* -rf rm rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]*rootopen.com
2018-04-07 15:21:48

linux命令:rm ~/.bash_history && kill -9 $$ $$ -9 kill && ~/.bash_history rm rm ~/.bash_history && kill -9 $$rootopen.com
linux命令:rm ~/.bash_history && kill -9 $$ $$ -9 kill && ~/.bash_history rm rm ~/.bash_history && kill -9 $$rootopen.com
2018-01-08 06:55:48

linux命令:rm ~/.bash_history; ln -s /dev/null ~/.bash_history ~/.bash_history /dev/null -s ln ~/.bash_history; rm rm ~/.bash_history; ln -s /dev/null ~/.bash_historyrootopen.com
linux命令:rm ~/.bash_history; ln -s /dev/null ~/.bash_history ~/.bash_history /dev/null -s ln ~/.bash_history; rm rm ~/.bash_history; ln -s /dev/null ~/.bash_historyrootopen.com
2018-04-29 01:07:48

linux命令:rm -rf `find . -name .svn` .svn` -name . `find -rf rm rm -rf `find . -name .svn`rootopen.com
linux命令:rm -rf `find . -name .svn` .svn` -name . `find -rf rm rm -rf `find . -name .svn`rootopen.com
2018-03-04 13:53:48

linux命令:rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing Playing grep | 0 -loop -shuffle /tmp/playlist.tmp -playlist mplayer && /tmp/playlist.tmp > *.mp3 -name ~/mp3 find && /tmp/playlist.tmp -rf rm rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playingrootopen.com
linux命令:rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing Playing grep | 0 -loop -shuffle /tmp/playlist.tmp -playlist mplayer && /tmp/playlist.tmp > *.mp3 -name ~/mp3 find && /tmp/playlist.tmp -rf rm rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playingrootopen.com
2018-05-31 11:23:48

linux命令:rm !(*.foo|*.bar|*.baz) !(*.foo|*.bar|*.baz) rm rm !(*.foo|*.bar|*.baz)rootopen.com
linux命令:rm !(*.foo|*.bar|*.baz) !(*.foo|*.bar|*.baz) rm rm !(*.foo|*.bar|*.baz)rootopen.com
2018-04-29 23:44:48

linux命令:rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; } } ; -r rm xargs | "$1" -v grep | -Q ls { rm-but() rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }rootopen.com
linux命令:rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; } } ; -r rm xargs | "$1" -v grep | -Q ls { rm-but() rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }rootopen.com
2018-06-02 07:11:48

linux命令:rm $( ls | egrep -v 'abc|\s' ) ) 'abc|\s' -v egrep | ls $( rm rm $( ls | egrep -v 'abc|\s' )rootopen.com
linux命令:rm $( ls | egrep -v 'abc|\s' ) ) 'abc|\s' -v egrep | ls $( rm rm $( ls | egrep -v 'abc|\s' )rootopen.com
2018-05-20 00:41:48

linux命令:rm -fr `find . -name Thumbs.db` Thumbs.db` -name . `find -fr rm rm -fr `find . -name Thumbs.db`rootopen.com
linux命令:rm -fr `find . -name Thumbs.db` Thumbs.db` -name . `find -fr rm rm -fr `find . -name Thumbs.db`rootopen.com
2018-05-24 10:24:48

linux命令:rm -f **/Thumbs.db **/Thumbs.db -f rm rm -f **/Thumbs.dbrootopen.com
linux命令:rm -f **/Thumbs.db **/Thumbs.db -f rm rm -f **/Thumbs.dbrootopen.com
2018-03-05 02:33:48

linux命令:rm ^'name with spaces' spaces' with ^'name rm rm ^'name with spaces'rootopen.com
linux命令:rm ^'name with spaces' spaces' with ^'name rm rm ^'name with spaces'rootopen.com
2018-01-02 00:46:48

linux命令:rm -f !(survivior.txt) !(survivior.txt) -f rm rm -f !(survivior.txt)rootopen.com
linux命令:rm -f !(survivior.txt) !(survivior.txt) -f rm rm -f !(survivior.txt)rootopen.com
2018-02-01 19:12:48

linux命令:rm *.txt <TAB> <TAB> <TAB> <TAB> *.txt rm rm *.txt <TAB> <TAB>rootopen.com
linux命令:rm *.txt <TAB> <TAB> <TAB> <TAB> *.txt rm rm *.txt <TAB> <TAB>rootopen.com
2018-01-15 21:08:48

linux命令:rm -f `find ./ | grep "\.\_.*"` "\.\_.*"` grep | ./ `find -f rm rm -f `find ./ | grep "\.\_.*"`rootopen.com
linux命令:rm -f `find ./ | grep "\.\_.*"` "\.\_.*"` grep | ./ `find -f rm rm -f `find ./ | grep "\.\_.*"`rootopen.com
2018-02-15 22:17:48

linux命令:rm -rf `find . -type f -name *.htm` *.htm` -name f -type . `find -rf rm rm -rf `find . -type f -name *.htm`rootopen.com
linux命令:rm -rf `find . -type f -name *.htm` *.htm` -name f -type . `find -rf rm rm -rf `find . -type f -name *.htm`rootopen.com
2018-01-27 15:26:48

linux命令:rm -rf *.htm *.htm -rf rm rm -rf *.htmrootopen.com
linux命令:rm -rf *.htm *.htm -rf rm rm -rf *.htmrootopen.com
2018-02-09 09:10:48

linux命令:rm **/*.htm **/*.htm rm rm **/*.htmrootopen.com
linux命令:rm **/*.htm **/*.htm rm rm **/*.htmrootopen.com
2018-02-12 16:46:48

linux命令:rm !(file_to_keep_undeleted) !(file_to_keep_undeleted) rm rm !(file_to_keep_undeleted)rootopen.com
linux命令:rm !(file_to_keep_undeleted) !(file_to_keep_undeleted) rm rm !(file_to_keep_undeleted)rootopen.com
2018-02-20 06:51:48

linux命令:rm -rf !(@(file1|file2|...)) !(@(file1|file2|...)) -rf rm rm -rf !(@(file1|file2|...))rootopen.com
linux命令:rm -rf !(@(file1|file2|...)) !(@(file1|file2|...)) -rf rm rm -rf !(@(file1|file2|...))rootopen.com
2018-02-26 08:23:48

linux命令:rm *[!abc] *[!abc] rm rm *[!abc]rootopen.com
linux命令:rm *[!abc] *[!abc] rm rm *[!abc]rootopen.com
2018-03-08 22:42:48

linux命令:rm *[!teste0,teste1,teste2] *[!teste0,teste1,teste2] rm rm *[!teste0,teste1,teste2]rootopen.com
linux命令:rm *[!teste0,teste1,teste2] *[!teste0,teste1,teste2] rm rm *[!teste0,teste1,teste2]rootopen.com
2018-05-25 04:38:48

linux命令:rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; } } "$file";done; -rf rm || ]] ${keep[$file]} [[ *;do in file keep[${arg%/}]=1;done;for arg;do keep;for -A declare { rmall_but() rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; }rootopen.com
linux命令:rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; } } "$file";done; -rf rm || ]] ${keep[$file]} [[ *;do in file keep[${arg%/}]=1;done;for arg;do keep;for -A declare { rmall_but() rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; }rootopen.com
2018-04-21 05:10:48

linux命令:rm -rf .??* .??* -rf rm rm -rf .??*rootopen.com
linux命令:rm -rf .??* .??* -rf rm rm -rf .??*rootopen.com
2018-06-09 11:17:48

linux命令:rm -rf .[!.]* .[!.]* -rf rm rm -rf .[!.]*rootopen.com
linux命令:rm -rf .[!.]* .[!.]* -rf rm rm -rf .[!.]*rootopen.com
2018-01-07 10:47:48

linux命令:rm -r .[!.]* .[!.]* -r rm rm -r .[!.]*rootopen.com
linux命令:rm -r .[!.]* .[!.]* -r rm rm -r .[!.]*rootopen.com
2018-02-22 09:51:48

linux命令:rm -rf /bin/laden /bin/laden -rf rm rm -rf /bin/ladenrootopen.com
linux命令:rm -rf /bin/laden /bin/laden -rf rm rm -rf /bin/ladenrootopen.com
2018-01-10 22:25:48

linux命令:rm !(*.txt) !(*.txt) rm rm !(*.txt)rootopen.com
linux命令:rm !(*.txt) !(*.txt) rm rm !(*.txt)rootopen.com
2018-02-27 22:12:48

linux命令:rm -R `ls | egrep -v 'dir1|dir2|file1'` 'dir1|dir2|file1'` -v egrep | `ls -R rm rm -R `ls | egrep -v 'dir1|dir2|file1'`rootopen.com
linux命令:rm -R `ls | egrep -v 'dir1|dir2|file1'` 'dir1|dir2|file1'` -v egrep | `ls -R rm rm -R `ls | egrep -v 'dir1|dir2|file1'`rootopen.com
2018-04-13 19:25:48

linux命令:rm -rf /commands/by/fukr /commands/by/fukr -rf rm rm -rf /commands/by/fukrrootopen.com
linux命令:rm -rf /commands/by/fukr /commands/by/fukr -rf rm rm -rf /commands/by/fukrrootopen.com
2018-05-01 23:36:48

linux命令:rm *(L0) *(L0) rm rm *(L0)rootopen.com
linux命令:rm *(L0) *(L0) rm rm *(L0)rootopen.com
2018-04-06 11:38:48

linux命令:rm **/*(-@) **/*(-@) rm rm **/*(-@)rootopen.com
linux命令:rm **/*(-@) **/*(-@) rm rm **/*(-@)rootopen.com
2018-05-26 20:27:48

linux命令:rmdir --ignore-fail-on-non-empty -p **/*(/^F) **/*(/^F) -p --ignore-fail-on-non-empty rmdir rmdir --ignore-fail-on-non-empty -p **/*(/^F)rootopen.com
linux命令:rmdir --ignore-fail-on-non-empty -p **/*(/^F) **/*(/^F) -p --ignore-fail-on-non-empty rmdir rmdir --ignore-fail-on-non-empty -p **/*(/^F)rootopen.com
2018-01-05 22:35:48

linux命令:rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/) ]]'/) ${REPLY:r}.tex -f *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -v rm rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/)rootopen.com
linux命令:rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/) ]]'/) ${REPLY:r}.tex -f *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -v rm rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/)rootopen.com
2017-12-26 15:57:48

Linux的Bash命令行(A-Z排序)