How to display the changed time using the Find command?

With the find I can display directory names with several levels. The following command displays all directories in the /var path with a depth of 2:

 find /var -maxdepth 2 -type d; 

Result:

 /var /var/log /var/log/sssd /var/log/samba /var/log/audit /var/log/ConsoleKit /var/log/gdm /var/log/sa 

With the stat command, I can find the modified date time:

 stat /var/log/samba | grep 'Modify:' 

Result:

 Modify: 2014-01-02 11:21:27.762346214 -0800 

Is there a way to combine the two commands so that the directories are listed with a modified date time?

+42
command-line linux grep find stat
Jan 02 '14 at
source share
5 answers

You can use the -exec switch to find and determine the output format of the stat using the -c switch as follows:

find /var -maxdepth 2 -type d -exec stat -c "%n %y" {} \;

This should indicate the name of the file, followed by the time it was modified on the same output line.

+38
Jan 02 '14 at 22:51
source share

The accepted answer works, but it is slow. There is no need for an exec stat for each directory, find provides the date of the change, and you can simply print it directly. Here the equivalent command is much faster:

  find /var -maxdepth 2 -type d -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tz\n" 
+68
03 Oct '14 at 16:53
source share

find /var -maxdepth 2 -type d | xargs ls -oAHd

This is a way to get your base ls display the full directory path. While ls has the -R option for recursive searches, paths will not appear in the results with the -l or -o option (at least on OSX), for ex with: ls -lR .

+7
Sep 12 '15 at 1:11
source share

try this line:

 find /var -maxdepth 2 -type d|xargs stat|grep -E 'File|Modi' 

here I ran it, it outputs:

 .... File: '/var/cache/cups' Modify: 2013-12-24 00:42:59.808906421 +0100 File: '/var/log' Modify: 2014-01-01 12:41:50.622172106 +0100 File: '/var/log/old' Modify: 2013-05-31 20:40:23.000000000 +0200 File: '/var/log/journal' Modify: 2013-12-15 18:56:58.319351603 +0100 File: '/var/log/speech-dispatcher' Modify: 2013-10-27 01:00:08.000000000 +0200 File: '/var/log/cups' Modify: 2013-12-22 00:49:52.888346088 +0100 File: '/var/opt' Modify: 2013-05-31 20:40:23.000000000 +0200 .... 
+1
Jan 02 '14 at 22:37
source share

Another that I use to print modified files on the last day. ls -ltr gives me a more detailed modification time, user, etc.

 find <my_dir> -mtime -1 -type f -print | xargs ls -ltr 
0
Aug 17 '17 at 10:06 on
source share



All Articles