{"id":2170,"date":"2021-09-29T07:17:09","date_gmt":"2021-09-29T06:17:09","guid":{"rendered":"http:\/\/linoxide.com\/how-tos\/touch-command-in-linux\/"},"modified":"2026-01-30T05:32:09","modified_gmt":"2026-01-30T05:32:09","slug":"touch-command-in-linux","status":"publish","type":"post","link":"https:\/\/linoxide.com\/touch-command-in-linux\/","title":{"rendered":"Touch Command in Linux (5 examples)"},"content":{"rendered":"\n<p>Touch command is commonly used to create an empty file in Linux. It can be also used to change file timestamps.<\/p>\n\n\n\n<p>In this tutorial, we learn about&nbsp;<strong>touch command in Linux<\/strong>&nbsp;with useful examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Linux Touch command<\/h2>\n\n\n\n<p>The touch command is used to update the access and modification time of a file.<\/p>\n\n\n\n<p>Syntax<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch &#91;<em>OPTION<\/em>] <em>FILE<\/em><\/code><\/pre>\n\n\n\n<p>Without any option, it creates an empty file assuming the file doesn\u2019t exist. If the file exists it change the timestamp. Touch cant open, save or close a file. You can use any text editor such as vi, vim, nano, or cat command to open the file created by the touch command.<\/p>\n\n\n\n<p>Let\u2019s go through how to use the touch command in Linux with examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Create an empty file<\/h2>\n\n\n\n<p>The following command creates a file named \u2018example1.txt\u2019.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch example1.txt<\/pre>\n\n\n\n<p>This file example1.txt won\u2019t have any contents. To confirm you can open with cat command (ie cat example1.txt).<\/p>\n\n\n\n<p>To create multiple empty files, type,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch example2.txt example3.txt<\/pre>\n\n\n\n<p>Remember If the file or directory already exists touch will update its access and modification time to the current time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Change file access and modification time<\/h2>\n\n\n\n<p>To change the file access and modification time on an existing file to current time run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch jmeter.log<\/code><\/pre>\n\n\n\n<p>From the output, you can see that both access and modification time changed for the file. You can get information about a file such as timestamps using the stat command.<\/p>\n\n\n\n<p>To change only the access time of an existing file, use the -a option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -a example2.txt<\/code><\/pre>\n\n\n\n<p>Similarly to change only the modification time of an existing file, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -m example3.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Set Specific Access and modification time<\/h2>\n\n\n\n<p>To set a specific date\/time for the access and modification timestamps use -t option.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -t YYYYDDHHMM.SS filename<\/code><\/pre>\n\n\n\n<p>For example to change access and modification date\/time of file named jmeter.log to 3rd Jan 2020, 3 PM, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -t 202001011500 jmeter.log<\/code><\/pre>\n\n\n\n<p>Alternatively, you can also use&nbsp;<code>-d<\/code>&nbsp;option to change access\/modification timestamps of a file to a specific date:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -d \u201801-October-2021\u2019 example3.txt<\/code><\/pre>\n\n\n\n<p>So using&nbsp;<code>-t<\/code>&nbsp;or&nbsp;<code>-d<\/code>&nbsp;options you can create a file with a specified time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Use the timestamp of another file<\/h2>\n\n\n\n<p>You can reference a file and use the same timestamp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -r example2.txt example3.txt<\/code><\/pre>\n\n\n\n<p>Here example3.txt will get the same timestamp as of example2.txt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Force not to create any files<\/h2>\n\n\n\n<p>Touch creates a new file if it doesn\u2019t exist. To force touch not to create a file use the -c option.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -c fileName<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this tutorial, we learned about touch command in Linux with useful examples. You can get more information from touch man pages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Touch command is commonly used to create an empty file in Linux. It can be also used to change file timestamps. In this tutorial, we learn about&nbsp;touch command in Linux&nbsp;with useful examples. Linux Touch command The touch command is used to update the access and modification time of a file. Syntax Without any option, it creates an empty file assuming the file doesn\u2019t exist. If the file exists it change the timestamp. Touch cant open, save or close a file. You can use any text editor such as vi, vim, nano, or cat command to open the file created by<\/p>\n","protected":false},"author":1,"featured_media":2169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-2170","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/2170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/comments?post=2170"}],"version-history":[{"count":1,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/2170\/revisions"}],"predecessor-version":[{"id":2194,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/2170\/revisions\/2194"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/media\/2169"}],"wp:attachment":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/media?parent=2170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/categories?post=2170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/tags?post=2170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}