The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help in script modification a.suryakumar Shell Programming and Scripting 4 03-12-2008 10:12 PM
crontab entry modification using shell script munishdh Shell Programming and Scripting 4 07-01-2007 02:47 AM
Specify a previous date as start date in shell script ritzwan0 Shell Programming and Scripting 2 09-25-2006 02:58 PM
Search by modification date slink UNIX for Dummies Questions & Answers 5 05-25-2006 03:07 AM
command for modification date of a file scampsd UNIX for Dummies Questions & Answers 5 12-28-2005 04:14 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-05-2006
Registered User
 

Join Date: Jul 2006
Posts: 7
Question Shell script: last modification date for a file

Hi i have a ques in Shell scripting:

ques: accept a filename as a command line argument. Validate the input and display the last modification date for that file.

Help pls.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-05-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
What have you done so far ?

Looks like homework..
Reply With Quote
  #3 (permalink)  
Old 07-05-2006
Registered User
 

Join Date: Jul 2006
Posts: 7
last modification date

What i have done is: accepted user input and done validation to check if the file is a valid one.
But i cant retrieve the last modification date...


I have tried using :
ls -l , put it into a file and then used cut command to display the date... but the cut command is not working!
Reply With Quote
  #4 (permalink)  
Old 07-05-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
you can try this..

ls -l filename|awk '{print $6 $7 $8}'

or if you want to catch in some variables for month,day,hour
use this in your script.

modf_time=`ls -l filename`

time_month=`echo $modf_time | awk '{print $6}'`
time_day=`echo $modf_time | awk '{print $7}'`
time_hrmin=`echo $modf_time | awk '{print $8}'`
time_hr=`echo $time_hrmin | cut -d ':' -f1`
time_min=`echo $time_hrmin | cut -d ':' -f2`

echo $time_month $time_day $time_hr $time_min
Reply With Quote
  #5 (permalink)  
Old 07-06-2006
Registered User
 

Join Date: Jul 2006
Posts: 7
Question Thanx!

Thank you...
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0