Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Last modified date of a directory in OSX

Tags:

shell

macos

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

like image 817
user754905 Avatar asked Apr 17 '12 19:04

user754905


2 Answers

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"
like image 141
je4d Avatar answered Oct 31 '22 17:10

je4d


ls -lcdoq your_directory | awk '{print $5" "$6}'
like image 45
Alex Avatar answered Oct 31 '22 18:10

Alex