How do I get the last modified date of a directory in terminal?
If you just want to get the modification date (mtime) and nothing else
stat --printf='%y\n' directory_name
or, for the date in seconds since the epoch:
stat --printf='%Y\n' directory_name
this is more straightforward, efficient and robust than solutions involving ls
/cut
/grep
/awk
/find
etc
Edit
The above was posted before the OP mentioned that this was for OSX in the comments below.
The OP arrived at a solution using stat
/date
, and I approve of the solution so I'm adding it here.
First the stat
stat -f "%m" /path/test.app
to get the directory's mtime, then wrap it in a date
to get it in the required format
date -j -f "%s" "$(stat -f "%m" /path/test.app)" +"%Y/%m/%d %T"
ls -lcdoq your_directory | awk '{print $5" "$6}'
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