«

»

Jan 02

Changing time stamp of a file in linux

Most of us would have thought of changing the  time stamp of a file, well its done using a command that we would have used several time,  but might have never thought of checking its manual.

I was surprised when I saw it for the first time, as I have been using this command since years, but never knew, what it was actually intended for.

 

We can change the time stamp of a file using “touch” command.

 

First we will create a file :

[[email protected] test]# touch noname
[[email protected] test]# stat noname 
  File: ‘noname’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: ca01h/51713d	Inode: 75539074    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2017-01-02 05:36:53.666076255 +0000
Modify: 2017-01-02 05:36:53.666076255 +0000
Change: 2017-01-02 05:36:53.666076255 +0000
 Birth: -
[[email protected] test]#

 

Now we would change access time of the file, for this we would use the following flags :

  • -a : to change access time
  • -t <YYYYMMDDHHSS> : to provide time
[[email protected] test]# touch -a -t 201605050200 noname 
[[email protected] test]# stat noname
  File: ‘noname’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: ca01h/51713d	Inode: 75539074    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-05-05 02:00:00.000000000 +0000
Modify: 2017-01-02 05:36:53.666076255 +0000
Change: 2017-01-02 05:39:23.425680365 +0000
 Birth: -
[[email protected] test]#

Here, we can see that only access time has been changes.

 

Similarly, we can change the Modify time as well, but for this we would have to execute the command without -a flag :

[[email protected] test]# touch -t 201605050200 noname 
[[email protected] test]# stat noname
  File: ‘noname’
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: ca01h/51713d	Inode: 75539074    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2016-05-05 02:00:00.000000000 +0000
Modify: 2016-05-05 02:00:00.000000000 +0000
Change: 2017-01-02 05:40:08.788043092 +0000
 Birth: -
[[email protected] test]# 

 

For more details, do refer the man page for “touch” command.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Warning: require_once(): open_basedir restriction in effect. File(/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php) is not within the allowed path(s): (/home/admin/web/linuxjoy.in/public_html:/home/admin/tmp) in /home/admin/web/linuxjoy.in/public_html/index.php on line 20

Warning: require_once(/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php): failed to open stream: Operation not permitted in /home/admin/web/linuxjoy.in/public_html/index.php on line 20

Fatal error: require_once(): Failed opening required '/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/admin/web/linuxjoy.in/public_html/index.php on line 20