删除当前目录下所有的*.txt文件,但除了test.txt文件:

rm `ls *.txt | grep -v test.txt`
或者
rm `ls *.txt | egrep -v test.txt`
或者
rm `ls *.txt | awk '{if($0 != "test.txt") print $0}'`
或者
rm `find . -name *.txt | grep -v test.txt`

 

排除多个文件:

rm `ls *.txt | egrep -v '(test.txt|fff.txt|ppp.txt)'

注意,这时只能用egrep,不可以用grep。而且(test.txt|fff.txt|ppp.txt)中不能有空格。

另外,还可以在排除字符中使用正则表达式。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-13
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案