So here's the deal. Let's say I have a directory named "web", so
$ ls -la drwx------ 4 rimmer rimmer 4096 2010-11-18 06:02 web
BUT inside this directory, web/php/
$ ls -la -rw-r--r-- 1 rimmer rimmer 1957 2011-01-05 08:44 index.php
That means that even though the content of my directory, /web/php/index.php has been last modified at 2011-01-05, the /web/ directory itself is reported as last modified at 2010-11-18.
What I need to do is have my /web/ directory's last modification date reported as the latest modification date of any file/directory inside this directory, recursively.
How do I go about doing this?
The syntax is pretty simple; just run the stat command followed by the file's name whose last modification date you want to know, as shown in the example below. As you can see, the output shows more information than previous commands.
ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.
Use “-mtime n” command to return a list of files that were last modified “n” hours ago. See the format below for a better understanding. -mtime +10: This will find all files that were modified 10 days ago. -mtime -10: It will find all files that were modified in the last 10 days.
Something like:
find /path/ -type f -exec stat \{} --printf="%y\n" \; | sort -n -r | head -n 1
Explanation:
If you have a version of find
(such as GNU find
) that supports -printf
then there's no need to call stat
repeatedly:
find /some/dir -printf "%T+\n" | sort -nr | head -n 1
or
find /some/dir -printf "%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1
If you don't need recursion, though:
stat --printf="%y\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