Bash 如何删除未以“;结尾的文件;。c”;在使用shell脚本的目录中?
我就这样试过了Bash 如何删除未以“;结尾的文件;。c”;在使用shell脚本的目录中?,bash,Bash,我就这样试过了 find -type f -name '*\.[^c]' -exec rm -f {} \; find . -type f |grep -v '.*\.c' | xargs rm -f 似乎它们不正确尝试使用否定您的姓名搜索 find -type f ! -name '*\.c' -exec rm -f {} \; 请使用delete命令尝试此操作: find -not -name "*.c" -type f -delete 字符的否定是不是模式匹配的^ -name '*.
find -type f -name '*\.[^c]' -exec rm -f {} \;
find . -type f |grep -v '.*\.c' | xargs rm -f
似乎它们不正确尝试使用
否定您的姓名搜索代码>
find -type f ! -name '*\.c' -exec rm -f {} \;
请使用delete命令尝试此操作:
find -not -name "*.c" -type f -delete
字符的否定是代码>不是模式匹配的^
-name '*.[!c]'
但这并不正确,因为这需要任何名称以点和单个字符结尾,而不是
如果您使用的是正则表达式,则需要使用锚点($):
但是以这种方式使用“grep”和xargs将无法正确处理带有空格或特殊字符的文件名
因此,如果您试图删除当前目录及其所有子目录中的文件,请尝试:
find . -type f ! -name "*.c" -exec rm -f {} +
-not
是的GNU
ism代码>。很好!你永远不会独行:)
find . -type f ! -name "*.c" -exec rm -f {} +