user754905
user754905

Reputation: 1809

Last modified date of a directory in OSX

How do I get the last modified date of a directory in terminal?

Upvotes: 7

Views: 8910

Answers (3)

je4d
je4d

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

Alex
Alex

Reputation: 11090

ls -lcdoq your_directory | awk '{print $5" "$6}'

Upvotes: 3

nes1983
nes1983

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

Related Questions