{"id":9079,"date":"2025-06-17T22:14:03","date_gmt":"2025-06-17T16:44:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=9079"},"modified":"2026-08-26T10:42:32","modified_gmt":"2026-08-26T05:12:32","slug":"modifying-file-timestamps-in-linux-using-touch","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/modifying-file-timestamps-in-linux-using-touch\/","title":{"rendered":"Modifying File Timestamps in Linux Using touch"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how to <strong>modify file timestamps in Linux using touch<\/strong>, covering the difference between access time, modification time, and change time, along with a key limitation most tutorials skip: the file&#8217;s birth (creation) time generally can&#8217;t be changed at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every file in Linux carries several timestamps as metadata:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Access time (<code>atime<\/code>)<\/strong> \u2014 the last time the file was read<\/li>\n\n\n\n<li><strong>Modification time (<code>mtime<\/code>)<\/strong> \u2014 the last time the file&#8217;s content was changed<\/li>\n\n\n\n<li><strong>Change time (<code>ctime<\/code>)<\/strong> \u2014 the last time the file&#8217;s metadata (permissions, ownership, etc.) was changed<\/li>\n\n\n\n<li><strong>Birth time<\/strong> \u2014 the file&#8217;s creation time, available only on certain filesystems and kernels<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>touch<\/code> command is commonly used to update the access and modification times \u2014 but as you&#8217;ll see below, Linux does not allow modification of the birth time using standard tools.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">I. Prerequisites<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To follow this guide, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Linux system (Ubuntu, Debian, CentOS, or similar)<\/li>\n\n\n\n<li>Terminal access with the necessary permissions (<code>sudo<\/code> or root, if working outside your own files)<\/li>\n\n\n\n<li>The <code>touch<\/code> command available (installed by default on all major distributions)<\/li>\n\n\n\n<li>A basic understanding of the <code>touch<\/code> timestamp format<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Timestamp format:<\/strong> <code>[[CC]YY]MMDDhhmm[.ss]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong> <code>202404200101.00<\/code> \u2192 April 20, 2024, at 01:01:00 AM<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">II. Create a Test File<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">touch new.txt\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Running <code>touch<\/code> on a file that doesn&#8217;t exist creates an empty file and sets its access and modification times to the current time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">III. Modify File Timestamps Using touch<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To set specific access and modification times:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">touch -a -m -t 202404200101.00 new.txt\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each flag does:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Flag<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>-a<\/code><\/td><td>Updates only the access time<\/td><\/tr><tr><td><code>-m<\/code><\/td><td>Updates only the modification time<\/td><\/tr><tr><td><code>-a -m<\/code> (together)<\/td><td>Updates both access and modification time to the same value<\/td><\/tr><tr><td><code>-t<\/code><\/td><td>Specifies the exact timestamp, in <code>[[CC]YY]MMDDhhmm[.ss]<\/code> format<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">IV. Verify the Changes<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">stat new.txt\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Expected output:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Access: 2024-04-20 01:01:00.000000000 +0000\nModify: 2024-04-20 01:01:00.000000000 +0000\nChange: [current time]\nBirth:  [unchanged, if supported]\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that <code>Change<\/code> still reflects the current time, not the value you set \u2014 this is expected, and explained below.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">V. Understand the Birth Time Limitation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the part most guides gloss over: birth time cannot be changed using <code>touch<\/code> or most standard Linux utilities. A few reasons why:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Most common Linux filesystems \u2014 <code>ext4<\/code>, <code>xfs<\/code>, <code>btrfs<\/code> \u2014 either don&#8217;t expose birth time editing at all, or restrict it at the kernel level<\/li>\n\n\n\n<li>Even when the <code>Birth<\/code> field is visible in <code>stat<\/code> output, it&#8217;s read-only and purely informational<\/li>\n\n\n\n<li>Some tools or environments may appear to &#8220;simulate&#8221; a birth time, but genuine modification isn&#8217;t possible with standard command-line utilities<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, <code>ctime<\/code> (change time) is <strong>not directly settable<\/strong> by design \u2014 it&#8217;s automatically updated by the kernel any time a file&#8217;s metadata changes, including as a side effect of running <code>touch<\/code> itself. This is intentional: <code>ctime<\/code> exists specifically as a tamper-evidence mechanism, so allowing it to be freely set would defeat its purpose.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">VI. Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Using <code>touch<\/code>, you can reliably modify <code>mtime<\/code> and <code>atime<\/code> to simulate past activity, backdate files for testing, or adjust metadata for specific auditing scenarios. Modifying the birth timestamp, however, isn&#8217;t supported due to how Linux filesystems are designed \u2014 and <code>ctime<\/code> updates automatically as a side effect of any metadata change, rather than being something you set directly. For practical day-to-day use, focus on <code>mtime<\/code> and <code>atime<\/code>, since those are the two timestamps you have full, reliable control over.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Can I set atime and mtime to different values in the same command?<\/strong> Yes \u2014 run <code>touch -t &lt;timestamp&gt;<\/code> without <code>-a<\/code> or <code>-m<\/code> to set both to the same value, or run two separate <code>touch<\/code> commands with <code>-a<\/code> and <code>-m<\/code> individually if you need different values for each.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why does ctime change even though I only modified atime and mtime?<\/strong> Because <code>touch<\/code> itself is a metadata-changing operation. The kernel automatically updates <code>ctime<\/code> any time a file&#8217;s inode metadata changes \u2014 including the very act of updating <code>atime<\/code> or <code>mtime<\/code> \u2014 which is why <code>ctime<\/code> can&#8217;t be set directly by design.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Is there any way to fake or set the birth time on Linux?<\/strong> Not reliably with standard tools. A small number of filesystem-specific or specialized utilities exist for niche use cases, but they aren&#8217;t part of standard Linux tooling and their behavior varies by filesystem, so they shouldn&#8217;t be relied on for general use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Related Articles:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-the-linux-kernel-handles-network-connections-using-dns-and-routing\/\" target=\"_blank\" rel=\"noreferrer noopener\">How the Linux Kernel Handles Network Connections Using DNS and Routing<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This guide explains how to modify file timestamps in Linux using touch, covering the difference between access time, modification [&hellip;]<\/p>\n","protected":false},"author":508,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-9079","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2mr","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/508"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9079"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9079\/revisions"}],"predecessor-version":[{"id":11076,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9079\/revisions\/11076"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}