Reputation: 33
I need to find all files with names matching different regular expressions in directories and subdirectories and print info about them.
For example, I have 3 directories:
/foo1
/foo1/foo2
/foo1/foo2/foo3
Files in this directories fgg1_1
fgg2_1
fgg3_1
:
/foo1/fgg1_1
/foo1/foo2/fgg2_1
/foo1/foo2/foo3/fgg3_1
And I need to find all files matching RE 'f.+1$'
. One might think to use
find /foo -regex 'f.+1$' -printf '%f %A@ %s \n'
but shurely it woun't match anything, because -regex evaluates full filenames e.g. /foo1/foo2/fgg2_1
.
I tried to grep the output, but it didn't help much since I still need to get info about files I find
find /foo -print '%f\n' | grep 'f.+1$'
It's important to note, that I'm looking for a somewhat universal solution since this command is executed on the remote host through ssh and compiled using python script, thus paths and RE's for file names can be different every time
You'll need to strip all ^
symbols from the beginning of filename's REs
find /foo -regex '.*\/f.+1$' -printf '%p %f %h %Y %G %U %A@ %C@ %T@ %s\n'
A bit of overkill, but I ended up using this because of how stat
displays c_time
find /foo | grep -e '.*\/f.+1$' | xargs stat --printf '%n %F %g %u %X %Z %Y %s %A\n'
Upvotes: 2
Views: 8606
Reputation: 101
To match whole paths that end in a filename matching a given regular expression, you could prepend .*/
to it, for example .*/f.+1$
. The .*/
should match the path preceding the filename.
Upvotes: 4
Reputation: 89
if you dont need regex you could try :
find /foo -name "fgg*" | xargs ls -l
Upvotes: 0