Operating System - HP-UX
1827500 Members
3575 Online
109965 Solutions
New Discussion

Re: Set file timestamp using informations of another file

 
SOLVED
Go to solution
SwissKnife
Frequent Advisor

Set file timestamp using informations of another file

Hi,

 

I have two files file1 and file2 like this.

ls -lrt file*

Feb  7 16:01 file1.log
Feb  8 13:23 file2.txt

 

I want to script something able to set file2 timestamp with file1 information to have this.

 

ls -lrt file*

Feb  7 16:01 file1.log
Feb  7 16:01 file2.txt

 

is touch -r file1 file2 is well enough ?

 Any ideas ?

 

kind regards, Den.

5 REPLIES 5
Steven Schweda
Honored Contributor

Re: Set file timestamp using informations of another file

> [...] set file2 timestamp with file1 information [...]

      man touch

   The big problem is parsing the "ls" output, and putting it into the
format required by "touch".  GNU "ls" has more date-time format options,
which might be more helpful than the usual HP-UX "ls".

   I'd probably look at writing a C program before trying to deal with
old-style "ls" output.

      man stat
      man utime


   Note that this is almost trivially easy on a VMS system, where
there's a standard date-time format, which is used for input and output
by nearly all common facilities.

Steven Schweda
Honored Contributor
Solution

Re: Set file timestamp using informations of another file

> is touch -r file1 file2 is well enough ?

   You tell us?  You may need to add "-a" and/or "-m", depending on
exactly what you want to do.

   (Why didn't I see "-r" the _first_ time I read the "man" page?)

SwissKnife
Frequent Advisor

Re: Set file timestamp using informations of another file

 

Hi,

 

thanks for your answer.Very appreciated.

Do you mean I could use some other flags to store all timestamp attributes (Access time, Modification time) ?

 

I have tried to find the syntax the combined syntax for -r -a -m but I did not find it.

 

 

 

Kind regards, Den.

 

SwissKnife
Frequent Advisor

Re: Set file timestamp using informations of another file

Hi,

 

How to have the same information after the touch -r for the file named aa..log ??

 


ORASIET2[root]/tmp # touch -r cfgvg.out aa.log
ORASIET2[root]/tmp # istat cfgvg.out
Inode 12 on device 10/7 File
Protection: rw-r--r--
Owner: 0(root)          Group: 0(system)
Link count:   1         Length 75 bytes

Last updated:   Tue Oct 18 10:19:48 2016
Last modified:  Tue Oct 18 10:19:48 2016
Last accessed:  Sun Feb  5 17:12:21 2017

ORASIET2[root]/tmp # istat aa.log
Inode 21 on device 10/7 File
Protection: rw-r--r--
Owner: 0(root)          Group: 0(system)
Link count:   1         Length 0 bytes

Last updated:   Wed Feb  8 16:28:55 2017
Last modified:  Tue Oct 18 10:19:48 2016
Last accessed:  Sun Feb  5 17:12:21 2017

 

 

Kind regards,

Den.

Dennis Handly
Acclaimed Contributor

Re: Set file timestamp using informations of another file

>I have tried to find the syntax the combined syntax for -r -a -m but I did not find it.

 

It's the obvious: touch -am -r ref_file file_name ...