除了一些RM的所有文件 [英] rm all files except some
本文介绍了除了一些RM的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用 sudo的RM -r
,我怎么可以删除所有文件,但下列除外:
TextFile.txt的
backup.tar.gz
script.php的
database.sql
信息.txt
解决方案
找到[路径]型的F - 不是-name'EXPR'-print0 | xargs的-0的RM -
例如,删除当前目录中的所有非TXT的文件:
找到。型的F - 不是-name'* TXT'-print0 | xargs的-0的RM -
查找| xargs的组合是非常有用的。
如果你不指定型F找到
也将列出目录,你可能不希望。
When using sudo rm -r
, how can I delete all files, with the exception of the following:
textfile.txt
backup.tar.gz
script.php
database.sql
info.txt
解决方案
find [path] -type f -not -name 'EXPR' -print0 | xargs -0 rm --
for example, delete all non txt-files in the current directory:
find . -type f -not -name '*txt' -print0 | xargs -0 rm --
The "find | xargs" combination is really useful.
If you don't specify "-type f" find
will also list directories, which you may not want.
这篇关于除了一些RM的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文