Amend File Without Changing Timestamp | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Amend File Without Changing Timestamp

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-04-2012
Ste_Moore01 Ste_Moore01 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 19 December 2012, 10:41 AM EST
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
Peasant Peasant is offline
Registered User
 
Join Date: Mar 2011
Last Activity: 1 November 2014, 2:48 AM EDT
Posts: 668
Thanks: 18
Thanked 150 Times in 146 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
Ste_Moore01 Ste_Moore01 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 19 December 2012, 10:41 AM EST
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
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 1 November 2014, 4:52 AM EDT
Location: San Jose, CA, USA
Posts: 4,940
Thanks: 186
Thanked 1,657 Times in 1,406 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
Ste_Moore01 Ste_Moore01 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 19 December 2012, 10:41 AM EST
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
Closed Thread

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 05:43 AM.