{"id":13250,"date":"2019-04-01T09:46:59","date_gmt":"2019-04-01T09:46:59","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13250"},"modified":"2019-04-01T09:46:59","modified_gmt":"2019-04-01T09:46:59","slug":"8-practical-examples-of-linux-touch-command","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/8-practical-examples-of-linux-touch-command\/","title":{"rendered":"8 Practical Examples of Linux \u201cTouch\u201d Command"},"content":{"rendered":"<p>In\u00a0<strong>Linux<\/strong>\u00a0every single file is associated with timestamps, and every file stores the information of last access time, last modification time and last change time. So, whenever we create new file, access or modify an existing file, the timestamps of that file automatically updated.<\/p>\n<div id=\"attachment_1736\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/12\/Touch-Command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1736\" title=\"Linux Touch Command\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/12\/Touch-Command-300x194.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/12\/Touch-Command-300x194.png 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/12\/Touch-Command.png 425w\" alt=\"Linux Touch Command\" width=\"300\" height=\"194\" aria-describedby=\"caption-attachment-1736\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-1736\" class=\"wp-caption-text\">Linux Touch Command Examples<\/p>\n<\/div>\n<p>In this article we will cover some useful practical examples of Linux\u00a0<strong>touch command<\/strong>. The\u00a0<strong>touch command<\/strong>\u00a0is a standard program for\u00a0<strong>Unix\/Linux<\/strong>\u00a0operating systems, that is used to create, change and modify timestamps of a file. Before heading up for touch command examples, please check out the following options.<\/p>\n<h3>Touch Command Options<\/h3>\n<ol>\n<li><strong>-a<\/strong>, change the access time only<\/li>\n<li><strong>-c<\/strong>, if the file does not exist, do not create it<\/li>\n<li><strong>-d<\/strong>, update the access and modification times<\/li>\n<li><strong>-m<\/strong>, change the modification time only<\/li>\n<li><strong>-r<\/strong>, use the access and modification times of file<\/li>\n<li><strong>-t<\/strong>, creates a file using a specified time<\/li>\n<\/ol>\n<h3>1. How to Create an Empty File<\/h3>\n<p>The following touch command creates an empty (zero byte) new file called\u00a0<strong>sheena<\/strong>.<\/p>\n<pre># touch sheena<\/pre>\n<h3>2. How to Create Multiple Files<\/h3>\n<p>By using touch command, you can also create more than one single file. For example the following command will create 3 files named,\u00a0<strong>sheena<\/strong>,\u00a0<strong>meena<\/strong>\u00a0and\u00a0<strong>leena<\/strong>.<\/p>\n<pre># touch sheena meena leena<\/pre>\n<h3>3. How to Change File Access and Modification Time<\/h3>\n<p>To change or update the last access and modification times of a file called\u00a0<strong>leena<\/strong>, use the\u00a0<strong>-a<\/strong>\u00a0option as follows. The following command sets the current time and date on a file. If the\u00a0<strong>leena<\/strong>\u00a0file does not exist, it will create the new empty file with the name.<\/p>\n<pre># touch -a leena<\/pre>\n<p>The most popular Linux commands such as\u00a0<a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">find command<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/15-basic-ls-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>\u00a0uses timestamps for listing and finding files.<\/p>\n<h3>4. How to Avoid Creating New File<\/h3>\n<p>Using\u00a0<strong>-c<\/strong>\u00a0option with touch command avoids creating new files. For example the following command will not create a file called\u00a0<strong>leena<\/strong>\u00a0if it does not exists.<\/p>\n<pre># touch -c leena<\/pre>\n<h3>5. How to Change File Modification Time<\/h3>\n<p>If you like to change the only modification time of a file called\u00a0<strong>leena<\/strong>, then use the\u00a0<strong>-m<\/strong>\u00a0option with touch command. Please note it will only updates the last modification times (not the access times) of the file.<\/p>\n<pre># touch -m leena<\/pre>\n<h3>6. Explicitly Set the Access and Modification times<\/h3>\n<p>You can explicitly set the time using\u00a0<strong>-c<\/strong>\u00a0and\u00a0<strong>-t<\/strong>\u00a0option with touch command. The format would be as follows.<\/p>\n<pre># touch -c -t YYDDHHMM leena<\/pre>\n<p>For example the following command sets the access and modification date and time to a file\u00a0<strong>leena<\/strong>\u00a0as\u00a0<strong>17:30<\/strong>(<strong>17:30 p.m<\/strong>.)\u00a0<strong>December 10<\/strong>\u00a0of the current year (<strong>2012<\/strong>).<\/p>\n<pre># touch -c -t 12101730 leena<\/pre>\n<p>Next verify the access and modification time of file\u00a0<strong>leena<\/strong>, with\u00a0<strong>ls -l<\/strong>\u00a0command.<\/p>\n<pre># ls -l\r\n\r\ntotal 2\r\n-rw-r--r--.  1 root    root   0 Dec 10 17:30 leena<\/pre>\n<h3>7. How to Use the time stamp of another File<\/h3>\n<p>The following touch command with\u00a0<strong>-r<\/strong>\u00a0option, will update the time-stamp of file\u00a0<strong>meena<\/strong>\u00a0with the time-stamp of\u00a0<strong>leena<\/strong>\u00a0file. So, both the file holds the same time stamp.<\/p>\n<pre># touch -r leena meena<\/pre>\n<h3>8. Create a File using a specified time<\/h3>\n<p>If you would like to create a file with specified time other than the current time, then the format should be.<\/p>\n<pre># touch -t YYMMDDHHMM.SS tecmint<\/pre>\n<p>For example the below command touch command with\u00a0<strong>-t<\/strong>\u00a0option will gives the\u00a0<strong>tecmint<\/strong>\u00a0file a time stamp of\u00a0<strong>18:30:55 p.m<\/strong>. on\u00a0<strong>December 10<\/strong>,\u00a0<strong>2012<\/strong>.<\/p>\n<pre># touch -t 201212101830.55 tecmint<\/pre>\n<p>We\u2019ve almost covered all the options available in the touch command for more options use \u201c<strong>man touch<\/strong>\u201c. If we\u2019ve still missed any options and you would like to include in this list, please update us via comment box.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/8-pratical-examples-of-linux-touch-command\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In\u00a0Linux\u00a0every single file is associated with timestamps, and every file stores the information of last access time, last modification time and last change time. So, whenever we create new file, access or modify an existing file, the timestamps of that file automatically updated. Linux Touch Command Examples In this article we will cover some useful &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/8-practical-examples-of-linux-touch-command\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;8 Practical Examples of Linux \u201cTouch\u201d Command&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13250","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13250"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13250\/revisions"}],"predecessor-version":[{"id":13251,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13250\/revisions\/13251"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}