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

2011. november 10., csütörtök

Listing files with multiple extensions with regex filtering

I just come across today looking at a developer's code how to list files with multiple extensions with one command. So, let's say if there are .zip, .tar, .txt files in a directory which I want to list with the 'ls' command. The metacharacters do not support extended regular expressions AFAIK, so I am left piping the output to a 'grep' command. I can use the following command to do it.

$ ls -1 | egrep ".*(gpg|txt|rpm)$"

That's nice! The above 'ls' output filtered by an extended grep (egrep) lists all 3 different file extensions what I wanted.