Operating System - HP-UX
1819796 Members
3133 Online
109607 Solutions
New Discussion юеВ

How to change timestamp of a file ?

 
SOLVED
Go to solution
Pulse001
Regular Advisor

How to change timestamp of a file ?

How can i change the timestamp of file ? it is showing 2008 as of now but i want files to show Oct 2008 to show as timestamp .
11 REPLIES 11
Steven Schweda
Honored Contributor

Re: How to change timestamp of a file ?

> How can i change the timestamp of file ?

"man touch".

> it is showing 2008 [...]

"Showing" how? At what are you looking?

> [...] i want files to show Oct 2008 to
> show as timestamp .

There's more in a file date-time than the
month and the year.
Prashanth Waugh
Esteemed Contributor
Solution

Re: How to change timestamp of a file ?

Hi,

touch -t

==================

-t time Use the specified time instead of the current time.
The option argument is a decimal number of the form:

[[CC]YY]MMDDhhmm[.SS]


Reagrds
Prashant
For success, attitude is equally as important as ability
AwadheshPandey
Honored Contributor

Re: How to change timestamp of a file ?

Can you pls more clear your purpose?
It's kind of fun to do the impossible
Suraj K Sankari
Honored Contributor

Re: How to change timestamp of a file ?

Hi,
This is how you can change the timestamp of a file with touch command, with -t time use the specified time instead of the current time. The option argument is a decimal number of the form: YYMMDDhhmm

$ touch -t YYMMDDhhmm

See this
$ date
Tue Oct 21 11:07:36 IST 2008
$ touch abc
$ ll abc
-rw-r--r-- 1 monitor testing 0 Oct 21 11:07 abc

$ touch -t 0810131020 abc
$ ll abc
-rw-r--r-- 1 monitor testing 0 Oct 13 10:20 abc

$ touch -t 0810130000 abc
$ ll abc
-rw-r--r-- 1 monitor testing 0 Oct 13 00:00 abc

$ touch -t 0710130000 abc
$ ll abc
-rw-r--r-- 1 monitor testing 0 Oct 13 2007 abc

Hope this will solved your problem.

Suraj
Pulse001
Regular Advisor

Re: How to change timestamp of a file ?

when i am typing ls -l my files till yesterday are showing as follows

Oct 20 08:48

but my file for today is only showing as

Oct 21 2008

i.e without the time being shown. So my dba is not able to track when did the dump complete/begin. He is able to track this only after the next day .
Dennis Handly
Acclaimed Contributor

Re: How to change timestamp of a file ?

>when i am typing ll my files till yesterday are showing as follows: Oct 20 08:48

That's correct. Files modified within the last 6 months show the date and time. Otherwise date and year. ls(1) says:
If the time of last modification is greater than six months ago, or any time in the future,

>but my file for today is only showing as Oct 21 2008

This file has a bogus timestamp. This is not within the last 6 months, it is a future time!

>i.e without the time being shown.

There is something wrong with the time on one of your machines, probably using NFS. Or you used touch(1) improperly. You need to do "date -u; date" on each of your machines and make sure they are all in sync.

I'm posting this about: Tue Oct 21 06:35 UTC 2008
Pulse001
Regular Advisor

Re: How to change timestamp of a file ?

Thanks Dennis,

o/p of date -u;date is

ggnhrdv4: /> date -u; date

Tue Oct 21 01:25:41 UTC 2008
Tue Oct 21 06:55:41 GMT 2008

Do you mean to say that the file in question is being written as of now and once it is completed it will show the time ?
Dennis Handly
Acclaimed Contributor

Re: How to change timestamp of a file ?

>Oct 21, 2008 06:59:30 GMT:
>Tue Oct 21 01:25:41 UTC 2008
>Tue Oct 21 06:55:41 GMT 2008

Your system has the wrong time. You are 5.5 hours slow!
Also, you have an illegal timezone setting.
Your GMT setting looks correct but UTC must also match.

So if you are in India, you must set TZ and /etc/TIMEZONE to IST-5:30
Then if you set your date to local time, your UTC time will match GMT.

What does this show?: echo $TZ
Pulse001
Regular Advisor

Re: How to change timestamp of a file ?

echo $TZ

GMT-5:30
Dennis Handly
Acclaimed Contributor

Re: How to change timestamp of a file ?

>echo $TZ => GMT-5:30

This is not a valid timezone, GMT is reserved. Using this just causes confusion. I.e. there is only one GMT timezone and that is "GMT0".
The times for GMT and UTC should always be the same.

So change your timezone to TZ=IST-5:30 and reset your system clock to local time.
Or use "date -u [mmddhhmm[[cc]yy]]" and set to UTC.
Pulse001
Regular Advisor

Re: How to change timestamp of a file ?

Thanks for the reply