File handling – UNIX stat

[problem]

You want to view seconds since last change or use Perl to process a number of files.

Or maybe you just want a programmatic way to deal with file details, using something similar to the UNIX stat C routine.

[/problem]

[solution]

Run stat against a file and display inode change time since epoch. See my other tip on converting to local time.

[/solution]

[example]

Excellent for showing the exact time in seconds, since the last change.

Rather than the normal hours and minutes from ls.

Replace /tmp/js with filename.

$ perl -e '$ctime=(stat("/tmp/js"))[10];print("$ctimen");'
1181102779

[/example]

[reference]

[tags]Perl file handling, Perl stat, UNIX stat, Perl Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

One Reply to “File handling – UNIX stat”

Leave a Reply

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