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.

Nincsenek megjegyzések: