I'm trying to run a command to find all files starting with 'geo' and see when they were edited. I am trying to following but unfortunately am having no luck..

Is there a param for stat to display the filename or do I need a multi-line bash script...

This works:

find . -name 'geo*' -exec stat -c%y {} \;

This doesn't:

# find . -name 'geo*' -exec echo {}&&stat -c%y {} \;
find: missing argument to `-exec'

You can use %n for the file name in stat

find . -name 'geo*' -exec stat -c '%y       %n' {} \;

Alternatively, you can print the file modification time as %Tk (where k is a datetime specifier similar to those used by the 'C' strftime function) and name %p directly from the find command e.g.

find . -name 'geo*' -printf '%Tc %p\n' 

or in a format closer to that of stat -y

find . -name 'geo*' -printf '%TY-%Tm-%Td %TT %Tz    %p\n'
| improve this answer | |


find . -name 'geo*' -exec stat -c%n\ %y {} \;

Use stat --help for more info

| improve this answer | |

It isn't working because the && that you append to the command:

execve("/usr/bin/find", ["find", ".", "-name", "geo*", "-exec", "echo", "{}"], [/* 56 vars */]) = 0
brk(0)                                  = 0x9914000

As you can see, the && is eaten up by the shell and never reach find. You can use PaulB solution in this case:

find . -name 'geo*' -exec stat -c%n%y {} \;
./.steam/ubuntu12_32/steam-runtime/i386/usr/share/X11/locale/georgian-academy2013-02-20 06:03:01.000000000 -0400
./.steam/ubuntu12_32/steam-runtime/i386/usr/share/X11/locale/georgian-ps2013-02-20 06:03:01.000000000 -0400
./.PlayOnLinux/fonts/georgiai.ttf2014-03-21 17:32:48.427937178 -0400
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.