LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-01-2004, 06:21 AM   #1
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Rep: Reputation: 30
How to calculate file age ? "File xy is 2 days 3 hours old"


Hello

I'm trying to make a list of the age or the elapsed time since the last modification of my files.

It should look this way:
File xy 2 days 3 hours 11 minutes
File yz 1 month 5 days 7 hours 23 minutes

I tried to do this with "ls -l" and awk for the values, but it's the wrong way.
I did not found anything like filedate - sysdate.


I prefer bash, put perl will be fine too :-)

TIA
Fluppi
 
Old 04-01-2004, 10:46 PM   #2
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Gentoo
Posts: 1,368

Rep: Reputation: 46
la -la

it will output like this:

drwxr-xr-x 2 exodist users 4096 Mar 31 00:45 azureus/

make a script that takes the date from the output and subtracts it from the current date, then have it output what you need. I cannot write this script inless than 1/2 hour, if u need help with scripting u can ask in the programming forum
 
Old 04-02-2004, 07:51 AM   #3
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Original Poster
Rep: Reputation: 30
I found the solution.

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

(Using ls-la will give you sometimes -32 minutes or too much to code ;-)
 
Old 06-23-2011, 12:57 PM   #4
aniserg
LQ Newbie
 
Registered: Jun 2011
Posts: 1

Rep: Reputation: Disabled
thx you fluppi!

this topic helped me! THX!
 
Old 03-14-2012, 05:45 AM   #5
voip.linux.expert
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
Thanks

This top helped me !

for oneliners, display age of the file in minutes:
OLD=`stat -c %Z file_name`; NOW=`date +%s`; (( DIFF = (NOW - OLD)/60 )) ; echo "This file is $DIFF m old"
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"bad interpreter : no such file or directory" when configure "flex" acer_peri Linux - Software 10 11-10-2010 01:19 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
decrypting a file using "crypt" & "rot13" JAMZM101 Solaris / OpenSolaris 1 03-07-2004 09:32 AM
Java does "age" or "Age" matter when declaring an Int?? Laptop2250 Programming 3 10-13-2003 12:34 PM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM


All times are GMT -5. The time now is 07:05 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration