2011. november 21., hétfő

Listing files with multiple extensions with find regex

The same as my previous blog not long before, I can list the files with the "find -regex" command but with a little trick. Thanks to http://stackoverflow.com/questions/353247/using-regex-to-find-files-with-certain-extensions .

$ [localhost: ~]$ find -regex ".*\.\(py\|gpg\)"
./macgen.py
./passwords.txt.gpg
./.gnupg/trustdb.gpg
./.gnupg/pubring.gpg
./.gnupg/secring.gpg
[localhost: ~]$

It lists the files of .py and .gpg extensions both with one single command. It works with a path if it is specified after the 'find' straight away.

$ [localhost: ~]$ find ./tmp -regex ".*\.\(py\|gpg\)"
./tmp/trustdb.gpg
./tmp/macgen.py
./tmp/passwords.txt.gpg
./tmp/pubring.gpg
./tmp/secring.gpg

1 megjegyzés:

Quartus Miklós írta...

and it's even better with adding the "-regextype" option, then you can use the real regular expressions, without the extra escape characters. For example:

$ find . -regextype posix-egrep -regex ".*.(py|gpg)"