Getting the Last Modification Timestamp of a File with Stat

If we want to get just the date modified, for a file, in a format of our choosing. This can be done with a utility called stat.

The syntax is as follows:

stat -f  -t "" 

In this example, we are printing just the date created in the format YYYYMMDD_HHMMSS.

stat -f "%Sm" -t "%Y%m%d_%H%M%S" filename.txt

We are using the -f “%Sm flag to specify that we want to print out only the date modified. The -t “%Y%m%d_%H%M%S” sets the date format.

In my example, the output was:

20121130_180221

This translates to November 30, 2012 at 18:02:21.

Leave a comment

Your email address will not be published. Required fields are marked *