troubleshooting Question

Shell scripting (ksh) to get file age

Avatar of jvossler
jvosslerFlag for United States of America asked on
System Programming
7 Comments1 Solution3065 ViewsLast Modified:

I am attempting to create a script that has as one of the function the determination of how old a file is.  I can use seconds, minutes, hours or days.  I have attempted to get the current epoch time via /usr/bin/perl -e 'printf "%d\n" , time;' and then use the stat perl function to get the files modifications date via

/usr/bin/perl -e 'printf "%d %d %d %d %d %d %d %d %d %d %d %d %d\n", stat("/NAS/${BKHOST}/${FNAME}.${SUFFIX}");' | awk '{print $11}'`

The problem is that the perl command will not make the variable substitutions and thus returns bogus information.

I am not set on using perl.  Any solution the I implement in ksh will work.  I just need to determine how old a file is in seconds, minutes, hours or days.  Parsing "ls" output is a problem due to older files having a year and newer files do not.

Any suggestions are helpful.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros