LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2011, 02:18 PM   #1
sasuke
LQ Newbie
 
Registered: Sep 2011
Location: Durgapur
Distribution: Red hat
Posts: 17

Rep: Reputation: Disabled
Changing timestamp


How to change the modification time and access time using touch command?
Is there any other way to do the same?
 
Old 09-16-2011, 02:29 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
For most UNIX/Linux commands there are manual pages called "man" pages which are accessed with the man command.

So if you type "man touch" you can find details about the touch command. Specifically it will show you the "-a" flag resets only access time and the "-m" flag resets only modification time. (If you don't use either than both are reset.) It will also show you the syntax to use.

You can also do such operations in many programming or scripting languages (such as C or Perl) but you'd have to look for specific details on what functions/libraries are used within those to do this.

You can also do kluges such as copying the original file to another file then copying it back. This would effectively change the times on the file (so long as you didn't use the "-p" flag of the "cp" command - see "man cp" for more details).

Finally Linux also has info pages in addition to man pages. Some detail for commands is in info on Linux rather than man whereas most UNIX flavors only use man.
 
Old 09-18-2011, 01:02 PM   #3
sasuke
LQ Newbie
 
Registered: Sep 2011
Location: Durgapur
Distribution: Red hat
Posts: 17

Original Poster
Rep: Reputation: Disabled
I tried by using the -a and -m options but it simply just creating a new file with the timestamp given.. could you please give an example of the respective command???
 
Old 09-18-2011, 07:47 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Can you show exactly what you did, as 'touch' only creates a new file if the file specified does not already exist: http://linux.die.net/man/1/touch
 
Old 09-19-2011, 11:27 AM   #5
sasuke
LQ Newbie
 
Registered: Sep 2011
Location: Durgapur
Distribution: Red hat
Posts: 17

Original Poster
Rep: Reputation: Disabled
i created a file emp.lst earlier . and then i used the touch command as 'touch -m 09191030 emp.lst; ll emp.lst'. But that only creates a file named 09191030. and the modification time is unaltered. what should i do in this case.
 
Old 09-19-2011, 11:35 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You need the -t option to specify the new timestamp. Also without -m and -a it will change all the three time specifications (access, modify and change). You can easily verify them using the stat command, e.g
Code:
$ stat file
<omitted>
Access: 2011-09-13 11:14:55.608030431 +0200
Modify: 2011-09-11 20:30:00.000000000 +0200
Change: 2011-09-13 11:13:20.122027834 +0200
$ touch -t 09191030 -m -a file
$ stat file
<omitted>
Access: 2011-09-19 10:30:00.000000000 +0200
Modify: 2011-09-19 10:30:00.000000000 +0200
Change: 2011-09-19 17:34:36.971028515 +0200
$ touch file
$ stat file
<omitted>
Access: 2011-09-19 17:36:23.499029022 +0200
Modify: 2011-09-19 17:36:23.499029022 +0200
Change: 2011-09-19 17:36:23.499029022 +0200
Please, read carefully the man pages.

Last edited by colucix; 09-19-2011 at 11:36 AM.
 
Old 09-19-2011, 11:51 AM   #7
sasuke
LQ Newbie
 
Registered: Sep 2011
Location: Durgapur
Distribution: Red hat
Posts: 17

Original Poster
Rep: Reputation: Disabled
thanks colucix it worked now. previously i did'nt use the -t option.
thanks again.....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
timestamp anaik100 Linux - General 7 11-15-2006 09:56 AM
about timestamp George2 Programming 1 08-16-2006 10:13 AM
Timestamp ancys Programming 5 08-07-2006 10:21 AM
timestamp cj24900 Linux - General 7 03-17-2006 01:05 PM
Timestamp Help jch02140 Linux - Newbie 7 03-17-2006 03:33 AM


All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration