Operating System - HP-UX
1832921 Members
2443 Online
110048 Solutions
New Discussion

Re: Change the date of file

 
SOLVED
Go to solution
O'lnes
Regular Advisor

Change the date of file

How to change the date of a file? Thanks.

eg.

From:
-rw-r--r-- 1 root sys 20000 Aug 22 01:25 file

To:
-rw-r--r-- 1 root sys 20000 Aug 21 01:25 file
Andy
8 REPLIES 8
Michael Tully
Honored Contributor

Re: Change the date of file

Try the 'touch' command

# touch -t 200208210125 test1
# ll test1
-rw-r--r-- 1 root sys 0 Aug 21 01:25 test1
Anyone for a Mutiny ?
RAC_1
Honored Contributor

Re: Change the date of file

touch command. Check touch man page
There is no substitute to HARDWORK
Patrick Chim
Trusted Contributor
Solution

Re: Change the date of file

Hi,

You can use touch to do that.

touch -t YYMMDDhhmm.SS filename
where YYMMDD is year to day
and hhmmSS is hour to second.

Regards,
Patrick
Michael Tully
Honored Contributor

Re: Change the date of file

I dont' want to play the points policeman, but your assignment of points to questions is not good. Please remember that people in the forums assist using their own spare time and resources to help you. Please abide by the forums etiquette and assign points to your questions.
Anyone for a Mutiny ?
O'lnes
Regular Advisor

Re: Change the date of file

Thx all.
Andy
John Bolene
Honored Contributor

Re: Change the date of file

touch only modifies the date that is normally shown

there are other dates associated with a file such as creation date
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
James R. Ferguson
Acclaimed Contributor

Re: Change the date of file

Hi:

The is *no* creation date for a file, only a *modification* date which the first time would be the same as a creation date.

There is also a last-access timestamp and a last-inode-change timestamp.

'touch' can be used to change the modification timestamp ('touch -m') or the last-access timestamp ('touch -a').

'ls -l' shows a file's modification timestamp.
'ls -ul' shows a file's last-access timestamp.
'ls -cl' shows a file's last inode change (change of permissions, ownership, etc.).

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Change the date of file

All answers give an 'absolute' answer. They don't apply to the question that probably was intended as "How do I put the dat of a file one day back?". Relative.



l1:/tmp 125 > ll xx
697 -rw-rw-rw- 1 merijn softwr 4306 Aug 22 17:19 xx
l1:/tmp 126 > perl -e'for(@ARGV){utime((map{$_-86400}(stat)[8,9]),$_)}' xx
l1:/tmp 127 > ll xx
697 -rw-rw-rw- 1 merijn softwr 4306 Aug 21 17:19 xx
l1:/tmp 128 >

l1:/tmp 130 > ll xx.*
861 -rw-rw-rw- 1 merijn softwr 71315 Aug 22 17:24 xx.html
869 -rw-rw-rw- 1 merijn softwr 128 Aug 9 17:17 xx.pl
686 -rwxrw-rw- 1 merijn softwr 3033 Jul 24 15:59 xx.txt
l1:/tmp 131 > perl -e'for(@ARGV){utime((map{$_-86400}(stat)[8,9]),$_)}' xx.*
l1:/tmp 132 > ll xx.*
861 -rw-rw-rw- 1 merijn softwr 71315 Aug 21 17:24 xx.html
869 -rw-rw-rw- 1 merijn softwr 128 Aug 8 17:17 xx.pl
686 -rwxrw-rw- 1 merijn softwr 3033 Jul 23 15:59 xx.txt
l1:/tmp 133 >


HTH
Enjoy, Have FUN! H.Merijn