Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-04-2012
Registered User
 
Join Date: Jul 2010
Posts: 24
Thanks: 8
Thanked 0 Times in 0 Posts
Amend File Without Changing Timestamp

Hi,

Is it possible to amend a file without changing the last modified date?

If it is, how do you do it?

If it's not, is there a way to create an empty file with the same timestamp as another file?

I know you can use touch -t yyyymmddhhmm.ss filename but, I would want the file to have the exact same timestamp as another file.

Any help would be greatly appreciated.

Thanks

****EDIT****
Sorry, I forgot to mention. I'm trying to script using bash.
Sponsored Links
    #2  
Old 12-04-2012
Peasant's Avatar
Registered User
 
Join Date: Mar 2011
Posts: 511
Thanks: 14
Thanked 104 Times in 102 Posts
You will use touch option -r (reference file) with will create a file with exact same timestamp as file you referenced to.

Check man touch
The Following User Says Thank You to Peasant For This Useful Post:
Ste_Moore01 (12-04-2012)
Sponsored Links
    #3  
Old 12-04-2012
Registered User
 
Join Date: Jul 2010
Posts: 24
Thanks: 8
Thanked 0 Times in 0 Posts
Thanks very much, Peasant.

I looked through the man page for touch and must've missed it.

Thanks!
    #4  
Old 12-04-2012
Registered User
 
Join Date: Jul 2012
Location: San Jose, CA
Posts: 1,476
Thanks: 62
Thanked 532 Times in 465 Posts
Actually:

Code:
touch -r file1 file2...

will set the access time and the modification time of file2 and any other file operands to match the access time and the modification time of file1. If you just want to reset the modification time, use:

Code:
touch -m -r file1 file2...

The Following User Says Thank You to Don Cragun For This Useful Post:
Ste_Moore01 (12-04-2012)
Sponsored Links
    #5  
Old 12-04-2012
Registered User
 
Join Date: Jul 2010
Posts: 24
Thanks: 8
Thanked 0 Times in 0 Posts
Thanks Don.

I realised what Peasant meant with his post and it worked perfectly.

Thanks for the info on touch -m though.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to compare a file by its timestamp and store in a different location whenever timestamp changes? mailsara UNIX for Dummies Questions & Answers 2 07-25-2011 03:48 PM
Getting a relative timestamp from timestamp stored in a file vaibhavkorde Shell Programming and Scripting 1 04-27-2011 06:08 AM
Changing timestamp file in crontab Zak UNIX for Advanced & Expert Users 4 04-30-2009 09:27 PM
Amend Unix hostname venhart UNIX for Advanced & Expert Users 3 03-11-2009 03:45 PM
changing timestamp of a file krishan Solaris 1 05-23-2005 10:50 AM



All times are GMT -4. The time now is 08:19 PM.