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
File timestamp stevefox UNIX for Dummies Questions & Answers 4 12-24-2007 10:14 PM
ftp - get file and keep original timestamp? frustrated1 Shell Programming and Scripting 2 03-15-2006 10:31 AM
comparing timestamp of two files jyotipg Shell Programming and Scripting 2 04-06-2004 03:38 AM
timestamp of file krisdhar UNIX for Dummies Questions & Answers 4 10-28-2003 07:31 AM
retrieve timestamp associated with a file 2nilotpal UNIX for Dummies Questions & Answers 2 08-08-2002 03:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-28-2008
Registered User
 

Join Date: Sep 2008
Posts: 1
Smile comparing timestamp of a file with its touched version

Hi,
I'm new to unix,I wanna know how can I compare timestamp of a file with its touched version.i.e I want to be sure if the touch command has worked properly i.e if the file has been touched then a msg should be printed saying success else failure.All this to be incurred in a script.
Any suggestions are welcome.

Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 09-28-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
If the stat(1) utility is available, then here is an example of one way of doing it
Code:
#!/bin/bash

FILE=./testfile        # replace with your file
stat1=$(stat --printf="%Z" $FILE)
touch $FILE
stat2=$(stat --printf="%Z" $FILE)
if [[ $stat1 = $stat2 ]]
then
   echo "touch failed"
else
   echo "touch succeeded"
fi
~
Reply With Quote
  #3  
Old 09-28-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 549
Quote:
Originally Posted by prince258 View Post
Hi,
I'm new to unix,I wanna know how can I compare timestamp of a file with its touched version.i.e I want to be sure if the touch command has worked properly i.e if the file has been touched then a msg should be printed saying success else failure.All this to be incurred in a script.
Any suggestions are welcome.

Thanks in advance
if you wanna check for the sucess or failuer of some command
check for $? after that command
e.g
Code:
 
touch filename
if [ $? -eq 0 ];then
echo "done"
else
echo "not done"
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:09 PM.


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

Content Relevant URLs by vBSEO 3.2.0