Skip to content
Advertisement

How to display modified date time with ‘find’ command?

With a find command, I can display directories names with multiple levels. The following command display all directories under /var path with a depth of 2:

JavaScript

The result shows:

JavaScript

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

JavaScript

The result is:

JavaScript

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

Advertisement

Answer

You could use the -exec switch for find and define the output format of stat using the -c switch as follows:

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

This should give the filename followed by its modification time on the same line of the output.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement