4

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'
Braiam
  • 67,791
  • 32
  • 179
  • 269
Menelaos
  • 141
  • 1
  • 1
  • 5

3 Answers3

3

Use:

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

Use stat --help for more info

Paul B
  • 434
2

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'
steeldriver
  • 136,215
  • 21
  • 243
  • 336
1

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
Braiam
  • 67,791
  • 32
  • 179
  • 269