{"id":16739,"date":"2023-09-11T19:22:42","date_gmt":"2023-09-11T19:22:42","guid":{"rendered":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/haydenjames.io\/?p=16739"},"modified":"2024-11-11T15:28:46","modified_gmt":"2024-11-11T15:28:46","slug":"touch-command-in-linux-w-examples","status":"publish","type":"post","link":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/","title":{"rendered":"touch command in Linux \/w examples"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16741 size-full\" title=\"touch command in Linux \/w examples\" src=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2023\/09\/touch_command_blog_image.png\" alt=\"touch command in Linux \/w examples\" width=\"868\" height=\"366\" srcset=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2023\/09\/touch_command_blog_image.png 868w, https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2023\/09\/touch_command_blog_image-300x126.png 300w, https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2023\/09\/touch_command_blog_image-560x236.png 560w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/p>\n<p>The <em>touch<\/em> command in Linux is a versatile tool for creating empty files or updating timestamps on existing ones. Despite its simplicity, it plays a crucial role in file management. In this article, we&#8217;ll delve into the basics of using the <em>touch<\/em> command in Linux, complete with practical examples to help you become proficient in file creation and timestamp management.<\/p><div class=\"hayden-after-paragraph hayden-entity-placement\" id=\"hayden-3828962027\"><div data-nosnippet id=\"hayden-1749117268\" style=\"margin-left: auto;margin-right: auto;text-align: center;\"><a data-no-instant=\"1\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/betterstack.com\/\" rel=\"noopener nofollow sponsored\" class=\"a2t-link\" target=\"_blank\" aria-label=\"Linux Logs and metrics: Better Stack\"><img fetchpriority=\"high\" loading=\"eager\" decoding=\"async\" src=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2025\/04\/logs-and-metrics-wide.png\" alt=\"Linux Logs and metrics: Better Stack\"  srcset=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2025\/04\/logs-and-metrics-wide.png 868w, https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2025\/04\/logs-and-metrics-wide-300x104.png 300w, https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-content\/uploads\/2025\/04\/logs-and-metrics-wide-560x194.png 560w\" sizes=\"(max-width: 868px) 100vw, 868px\" width=\"868\" height=\"300\"  style=\"display: inline-block;\" \/><\/a><\/div><div align=\"center\" style=\"font-style: italic; font-size: 0.85em; font-weight: normal; margin-top: 4px;\">\r\n\tAdvertisement\r\n<\/div><\/div>\n<p>This article is a follow-up to the previous\u00a0<a title=\"90 Linux Commands frequently used by Linux Sysadmins\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/90-linux-commands-frequently-used-by-linux-sysadmins\/\" target=\"_blank\" rel=\"bookmark noopener\">90 Linux Commands frequently used by Linux Sysadmins<\/a>\u00a0post. As time allows, I will continue to publish articles on each of these 90 commands geared toward Linux sysadmins and Linux power users.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><div class=\"ez-toc-title\" style=\"cursor:inherit\">In This Article<\/div>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Understanding_the_touch_Command\" >Understanding the touch Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Touch_Command_to_Create_Empty_Files\" >Touch Command to Create Empty Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Use_touch_to_Create_Multiple_Files\" >Use touch to Create Multiple Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Setting_Timestamps_with_touch\" >Setting Timestamps with touch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#touch_Common_Options\" >touch Common Options<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Timestamp_Manipulation\" >Timestamp Manipulation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/touch-command-in-linux-w-examples\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Understanding_the_touch_Command\"><\/span>Understanding the <code>touch<\/code> Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we dive into examples, let&#8217;s grasp the basic syntax of the <code>touch<\/code> command:<\/p>\n<pre>touch [options] file(s)<\/pre>\n<ul>\n<li><code>[options]<\/code>: These are optional flags that modify the behavior of the <code>touch<\/code> command. We&#8217;ll cover some common options in the examples.<\/li>\n<li><code>file(s)<\/code>: These are the names of the files you want to create or update.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Touch_Command_to_Create_Empty_Files\"><\/span><code>Touch<\/code> Command to Create Empty Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The primary function of the <code>touch<\/code> command is to create empty files. Here&#8217;s how to create a single empty file:<\/p>\n<pre>touch my_file.txt<\/pre>\n<p>This command creates a file named <code>my_file.txt<\/code> in the current location. If the file already exists, it updates its timestamp without altering its contents.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_touch_to_Create_Multiple_Files\"><\/span>Use <code>touch<\/code> to Create Multiple Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can create multiple empty files at once by specifying their names:<\/p>\n<pre>touch file1.txt file2.txt file3.txt<\/pre>\n<p>This command creates three empty files: <code>file1.txt<\/code>, <code>file2.txt<\/code>, and <code>file3.txt<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Setting_Timestamps_with_touch\"><\/span>Setting Timestamps with <code>touch<\/code><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Besides creating files, the <code>touch<\/code> command is handy for modifying timestamps. You can specify a timestamp using the <code>-t<\/code> (timestamp) option in the format <code>[[CC]YY]MMDDhhmm[.ss]<\/code>:<\/p>\n<pre>touch -t 202108301530 my_file.txt<\/pre>\n<p>This command sets the timestamp of <code>my_file.txt<\/code> to August 30th, 2021, at 15:30.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"touch_Common_Options\"><\/span><code>touch<\/code> Common Options<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here are some common options used with the <code>touch<\/code> command:<\/p>\n<ul>\n<li><code>-c<\/code> (no create): Prevents file creation if the file doesn&#8217;t exist.<\/li>\n<li><code>-d<\/code> (date): Uses a specified date\/time instead of the current date.<\/li>\n<li><code>-t<\/code> (timestamp): Sets a custom timestamp, as demonstrated above.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Timestamp_Manipulation\"><\/span>Timestamp Manipulation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Manipulating timestamps can be valuable for various tasks, such as organizing files, backup management, and version control. The <code>touch<\/code> command&#8217;s <code>-t<\/code> and <code>-d<\/code> options allow you to precisely control these timestamps.<\/p>\n<p>Additionally, for more advanced timestamp manipulation and scripting, consider tools like <code>touch<\/code> combined with <code>date<\/code> and <code>find<\/code> commands.<\/p>\n<p><em>Reference: <\/em><a href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/www.ibm.com\/docs\/pl\/aix\/7.1?topic=t-touch-command\" target=\"_blank\" rel=\"noopener\"><em>IBM touch command<\/em><\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>touch<\/code> command is a simple yet indispensable tool in Linux for file creation and timestamp management. Whether you need to create empty files, update timestamps, or set custom dates, it offers flexibility and efficiency. By mastering the <code>touch<\/code> command, you can become more proficient in file management and timestamp manipulation in the Linux environment.<\/p>\n<p>Now that you&#8217;ve learned the essentials of the <code>touch<\/code> command, you can confidently create and manipulate files with precision.<\/p>\n<p>If you\u2019re interested in expanding your knowledge of Linux commands and want to explore more frequently used commands by Linux sysadmins, I recommend checking out the parent article at the following link:\u00a0<a href=\"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/90-linux-commands-frequently-used-by-linux-sysadmins\/\" target=\"_new\" rel=\"noopener\">90 Linux Commands Frequently Used by Linux Sysadmins<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The touch command in Linux is a versatile tool for creating empty files or updating timestamps on existing ones. Despite its simplicity, it plays a crucial role in file management. In this article, we&#8217;ll delve into the basics of using the touch command in Linux, complete with practical examples to help you become proficient in [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"publish_to_discourse":"1","publish_post_category":"54","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"5392","discourse_permalink":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxcommunity.io\/t\/touch-command-in-linux-w-examples\/2656","wpdc_publishing_response":"","wpdc_publishing_error":"","footnotes":""},"categories":[1,11],"tags":[117,49],"class_list":["post-16739","post","type-post","status-publish","format-standard","hentry","category-articles","category-linux","tag-commands","tag-sysadmins"],"_links":{"self":[{"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/posts\/16739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/comments?post=16739"}],"version-history":[{"count":1,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/posts\/16739\/revisions"}],"predecessor-version":[{"id":18970,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/posts\/16739\/revisions\/18970"}],"wp:attachment":[{"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/media?parent=16739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/categories?post=16739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/linuxblog.io\/wp-json\/wp\/v2\/tags?post=16739"}],"curies":[{"name":"wp","href":"https:\/\/round-lake.dustinice.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}