Monday, December 1, 2014

Stat - just the facts, ma'am

Stat is a useful tool on Linux that wraps the stat system call to return all available info about a file, and prints it out neatly. I wanted an abbreviated output - just atime, mtime and ctime. Rather than pipe stat's output through something else to strip out the lines I didn't want. I used the stat utility's --printf option to output just the bits I wanted:

$ stat --printf="atime: %x\nmtime: %y\nctime: %z\n" /tmp/testfile
atime: 2014-12-02 09:57:01.890339130 +1100
mtime: 2014-12-02 09:58:31.066781362 +1100
ctime: 2014-12-02 09:58:31.066781362 +1100


Yay for stat (and reading the man page once in a while!)

No comments:

Post a Comment