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\)"
[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\)"

1 megjegyzés:

Miklós Quartus í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)"