2013-11-23 53 views

回答

0

备份你的目录第一,我没有测试过这个,它有一个错误,如注释中所述。

,而在实际的/源目录:

ls|fgrep -v -e .tar -e .patch|xargs rm -rf 

你可能想使用的伎俩“xargs的后摆回声”,看看这实际上做,运行它之前:

ls|fgrep -v -e .tar -e .patch|xargs echo rm -rf 
+1

谢谢!这个工作正常! – gaia

+1

如果有空格的文件名,这实际上会中断。 “-1”表示对整个世界和未来世代的不良做法。 –

+0

@gniourf_gniourf随时编辑我的答案以纠正错误 –

1

这应该工作:

find . -not -name "*.tar" -not -name "*.patch" -type f -exec rm {} \; 

这只使用一个不使用pipes的命令。

注意。这将递归进入子目录。如果这是不需要的,请使用maxdepth开关:

find . -maxdepth 1 -not -name "*.tar" -not -name "*.patch" -type f -exec rm {} \; 
相关问题