find filenames NOT ending in specific extensions on Unix?

前端 未结 8 1604
悲&欢浪女
悲&欢浪女 2020-11-30 17:26

Is there a simple way to recursively find all files in a directory hierarchy, that do not end in a list of extensions? E.g. all files that are not *.dll or *.exe

8条回答
  •  执念已碎
    2020-11-30 17:34

    Linux/OS X:

    Starting from the current directory, recursively find all files ending in .dll or .exe

    find . -type f | grep -P "\.dll$|\.exe$"
    

    Starting from the current directory, recursively find all files that DON'T end in .dll or .exe

    find . -type f | grep -vP "\.dll$|\.exe$"
    

    Notes:

    (1) The P option in grep indicates that we are using the Perl style to write our regular expressions to be used in conjunction with the grep command. For the purpose of excecuting the grep command in conjunction with regular expressions, I find that the Perl style is the most powerful style around.

    (2) The v option in grep instructs the shell to exclude any file that satisfies the regular expression

    (3) The $ character at the end of say ".dll$" is a delimiter control character that tells the shell that the filename string ends with ".dll"

提交回复
热议问题