Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What is the simplest way to output file ages instead of filedates by ls command?

Like "1 hour", "2 days", "3 weeks", etc.

(Sometimes file age is much more significant than date)

share|improve this question
    
Gnome's Nautilus does something similar. Perhaps you can check how it's done there? –  Bram Jun 13 '12 at 19:22
add comment

1 Answer 1

I get the UNIX-Systemdate in seconds with NOW=date +%s Then I get the UNIX-Timestamp of the file with OLD=stat -c %Z filename

And finally I get the age by expr $NOW - $OLD.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.