{"id":33,"date":"2007-11-01T23:28:56","date_gmt":"2007-11-01T15:28:56","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/unix-quick-tip-changing-the-time-stamp-of-a-file\/"},"modified":"2007-11-01T23:28:56","modified_gmt":"2007-11-01T15:28:56","slug":"unix-quick-tip-changing-the-time-stamp-of-a-file","status":"publish","type":"post","link":"http:\/\/www.sysadmindayph.com\/blog\/unix-quick-tip-changing-the-time-stamp-of-a-file\/","title":{"rendered":"UNIX Quick Tip: Changing The Time Stamp Of A File"},"content":{"rendered":"<p>This tip is a give away. Everyone knows this, but for those who doesn&#8217;t or forgot&#8230;\u00a0 here&#8217;s refresher&#8230;<\/p>\n<p>Here&#8217;s a typical output of a file listing using `ls -l` on a directory:<\/p>\n<blockquote><p>[root@unix-box icons]# ls -l | more<br \/>\ntotal 636<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 246 Aug 26\u00a0 2005 a.gif<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 242 Aug 26\u00a0 2005 alert.black.gif<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 279 Aug 26\u00a0 2005 alert.black.png<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 247 Aug 26\u00a0 2005 alert.red.gif<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 298 Aug 26\u00a0 2005 alert.red.png<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2326 Aug 26\u00a0 2005 apache_pb.gif<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1385 Aug 26\u00a0 2005 apache_pb.png<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 293 Aug 26\u00a0 2005 a.png<\/p><\/blockquote>\n<p>When using the -l (dash &#8216;el&#8217;) option of ls, the output will display a more detailed listing of the files. Here you&#8217;ll see the file properties\/permission (-rw-r&#8211;r&#8211;) the number of links, the owner of the file, the group of the user, file size, the date\/time stamp and finally the file name. That&#8217;s 7 column.<\/p>\n<p><strong>Changing The Time Stamp Of A File<\/strong><\/p>\n<p>To change the time stamp of a file (the 6th column in the `ls -l` listing), we use the UNIX command <strong>touch<\/strong>.<\/p>\n<p>From the Man Pag:<\/p>\n<blockquote><p>NAME<br \/>\ntouch &#8211; change file timestamps<\/p>\n<p>SYNOPSIS<br \/>\ntouch [OPTION]&#8230; FILE&#8230;<br \/>\ntouch [-acm] MMDDhhmm[YY] FILE&#8230; (obsolescent)<\/p><\/blockquote>\n<p>There are many options for the <em>touch <\/em>command, but the one I use fairly often is the -t option<\/p>\n<blockquote><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -t STAMP; \u00a0\u00a0 use [[CC]YY]MMDDhhmm[.ss]<\/p><\/blockquote>\n<p>Example:<\/p>\n<blockquote><p>\u00a0[root@unix-box icons]#\u00a0 touch -t 200607161201 a.gif<br \/>\n[root@unix-box icons]# ls -l | more<br \/>\ntotal 636<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 246 Jul 16\u00a0 2006 a.gif<br \/>\n-rw-r&#8211;r&#8211;\u00a0\u00a0\u00a0 1 elizar root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 242 Aug 26\u00a0 2005 alert.black.gif<\/p><\/blockquote>\n<p>Other options that you\u00a0 may find useful are -a (change access time only) -m (modification time only) and others. Consult the man page for more details<\/p>\n<p>Cheers!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tip is a give away. Everyone knows this, but for those who doesn&#8217;t or forgot&#8230;\u00a0 here&#8217;s refresher&#8230; Here&#8217;s a typical output of a file listing using `ls -l` on a directory: [root@unix-box icons]# ls &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,8,3],"tags":[],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-linux","category-tips","category-unix"],"_links":{"self":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}