Ben
Ben

Reputation: 62504

Getting the last modification time of a directory

I understand this isn't the actual "modification" time of a directory, but I need the timestamp and I'm struggling to determine how to get it. I'm actually going to use the output of this command in a PHP script, but I can't get the time.

stat -f "%y" zip

I keep getting the message stat: cannot read file system information for '%y': No such file or directory

Upvotes: 0

Views: 325

Answers (3)

Steve Zobell
Steve Zobell

Reputation: 884

I prefer find over stat. Find may have better formatting options and may be more consistent and available across platforms.

find zip -maxdepth 0 -printf "%TY/%Tm/%Td %TH:%TM:%.2TS\n"
2011/11/21 13:41:36

Be sure to include -maxdepth, otherwise find will dig out all the files under the directory.

Upvotes: 1

Andreas
Andreas

Reputation: 5335

you could use the SplFileInfo class to get the modification time of the directory

$test = new SplFileInfo(__DIR__); //use a path to your directory
echo  $test->getMTime();
echo date('Y-m-d',$test->getMTime());

Upvotes: 1

Antti
Antti

Reputation: 12489

%y is used for defining the output format. You can only set the output format after the -c flag. What you want is:

stat -c %y zip

Upvotes: 1

Related Questions