4

I want to delete all files in a directory with a given name, except for one with a given extension. I.e. we have a directory with:

foo.txt foo.exe foo.jpg foo.png foo.something foo.somethingelse bar.jpg bar.exe

I want to get rid of foo.txt foo.jpg foo.png foo.something foo.somethingelse

BUT crucially I don't want to get rid of foo.exe

Is there an easy one liner to do this?

Thank you

4

1 回答 1

7

您可以在命令!内部使用find来排除事物,例如:

find . -maxdepth 1  -type f  -name "foo.*"  ! -name foo.exe  -exec rm '{}' \;
       -----------  -------  -------------  ---------------  ----------------
       in this dir   files    named foo.*   but not foo.exe  ...destroy them.

那应该删除foo.*当前目录中匹配的文件,但不要foo.exe理会。

于 2012-06-18T11:09:10.170 回答