Reputation: 1809
How do I get the last modified date of a directory in terminal?
Upvotes: 7
Views: 8910
Reputation: 7838
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"
Upvotes: 11
Reputation: 15756
Recursive:
ls -Rlt | head -n 2 | cut -d ' ' -f10-12
Non-recursive:
ls -lt | head -n 2 | cut -d ' ' -f10-12
Upvotes: 1