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:
find /var -maxdepth 2 -type d;
The result shows:
/var /var/log /var/log/sssd /var/log/samba /var/log/audit /var/log/ConsoleKit /var/log/gdm /var/log/sa
With a stat
command, I can find the modified date time:
stat /var/log/samba | grep 'Modify:'
The result is:
Modify: 2014-01-02 11:21:27.762346214 -0800
Is there a way to combine the two commands so that directories will be listed with modified date time?
Windows file properties You can also see the modified date by viewing the file properties. Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.
You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option. -mtime +60 means you are looking for a file modified 60 days ago.
Linux Commands - find command - date accessed (-atime) The -atime option can be used to return files and directories that were accessed x or more days ago. For example, to return files and directories that were accessed 14 or more days ago below the tmp directory.
For example, to get the last modified time for the file ‘E:commands.docx’ the command would be: To get the modified date and time for all files and sub folders in the current directory the command would be: Using Forfiles command. Using forfiles command we can get modified date and time for all the files in a directory.
Please note that /D + (number of days) is practically not useful. This option says to search for the files modified after n days from today’s date. If there are no files meeting the condition, the command prints the following message.
To get the modified date and time for all files and sub folders in the current directory the command would be: dir /T:W. To get modified date/time only for files in the current directory(i.e exclude directories from files) dir /T:W /A:-D.
‘find’ is a very powerful Linux command which provides various options for searching files based on different criteria. One of these options allows users to search for files based on the modification/access/creation time of the file.
The accepted answer works but it's slow. There's no need to exec stat for each directory, find provides the modification date and you can just print it out directly. Here's an equivalent command that's considerably faster:
find /var -maxdepth 2 -type d -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tz\n"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With