Hi,
I'm using the following command to find the multiple requierd file types and its working fine
find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f
Though above command workswell and good, but the command is lengthier and difficult to edit or parameterize.
I'm looking to simplify it so that it can be easily editable in a script in future .
Please help me if anyone could simplify the problem.
Note : I cant use "*.*" as its gonna search all the files.
Thanks
Vikram shetty
Maybe
find . -type f | egrep '.pl$|.pm$|.sql$|.so$|.sh$|.java$|.class$|.jar$|.gz$|.Z$'
or
find . -type f | egrep '.p[lm]$|.sql$|.s[oh]$|.java$|.class$|.jar$|.gz$|.Z$'
1 Like
If you're using GNU find, you can use the -regex option:
find ./ -regextype posix-extended -regex ".*\.(pl|pm|sql|so|sh|java|class|jar|gz|Z)"
If you don't have GNU find, you can use egrep:
find ./ -type f | egrep "\.(pl|pm|sql|so|sh|java|class|jar|gz|Z)$"
Note the slight difference between the grep and find regexes. Find assumes the regex should match the entire line. For grep we only need to tell it to match the extension, and append $ to the end to tell it that must be at the end of the line to match.
1 Like