8 Practical Examples of Linux “Touch” Command

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

21 Responses

  1. Mike says:

    *Practical <-typo in title and html title

  2. Neeraj Rawat says:


    Nice coverage of touch as per the man pages, but I think the article would be more useful if you cover the scenarios to use touch. In which scenario one would like to use the following options.

    If you modify the file then modify time changes. How come ls -l gives the access time? Did you check it? Doesn’t it only list the modify time.

    If you use touch -a then the output of ls -l doesn’t change, however try it with touch -m to notice the output.

  3. Matt-Boy says:

    This may be behavior specific to the Apple/Mac implementation of TOUCH, but I figured one additional thing out. The touch command does not have an option to update the CREATION date of a file. However, if you use touch to update the modification date, and that date is before/earlier than the creation date, the creation date will be updated as well.

  4. Marc G says:

    At 6. Explicitly Set the Access and Modification times you write for the format:
    [# touch -c -t YYDDHHMM leena]
    Should it not be: YYMMDDHH ?
    Two digits for the year (the last two) is fine, but followed by DD which should
    mean the DAY doesn’t make sense.
    The info (MAN) page for “touch” says “-t [[CC]YY]MMDDHHMM[.SS]”.
    I’m here because I’m getting a “touch: invalid date format ‘15062500’”, after doing
    “touch -c -t 15062500 my-file.txt”. That’s June 25, 2015, 00h(00).
    Trying to figure it out.

    • Ravi Saive says:

      Do this way..

      [email protected] ~/renamefiles $ touch -c -t 1506250000 my-file.txt
      [email protected] ~/renamefiles $ ls -l
      total 0
      -rw-r--r-- 1 tecmint tecmint 0 Jun 25 00:00 my-file.txt
      • Marc G. says:

        Yes, thank you, I got it. I was omitting the dot before the seconds and
        doing as if the minutes were optional. They are not. It’s the seconds
        that are optional.

        But really you should edit your original post and replace YYDDHHMM
        with MMDDHHMM. That was a misprint. You cannot have day following

        Thanks again.

  5. venkat says:

    Thank you for these tips/
    The basics of the command “touch” are covered very well, in a simple manner.


  6. Abhishek Yadav says:

    Nice tutorials…covers basics of ‘touch’ fair enough !!

  7. Hej

    I use Ubuntu 14.04, when I use touch like this:

    touch -t 195312100101 sekt-0001.jpg

    Then the file icon i filer have a clock on it why?

    I can still use the picture

  8. Lucas says:

    Out of curiosity, any idea how the touch command got its name?

    • Matt-Boy says:

      I think the idea is that you are just “touching” the file so it records that it was accessed/modified, but you are not actually changing the file in any other way. Note that there are no options to modify the content of the file itself.

      • Ravi Saive says:

        Yes, you correct and I totally agree with your point, we are only touching the file, no modifications, but it records as accessed/modified time.

  9. MykeC says:

    How does one update the modification timestamp of a file to become its current value plus one second?

    I would like to write a shell script which does this easily to any group of files as needed.

  10. Santhosh says:

    Nice post & it’s very useful.

    One small correction here. I think the following command will update the time-stamp of file meena with the time-stamp of leena file.

    $ touch -r leena meena

    Will you check it.


    • Ravi Saive says:

      Dear Vijay,

      Thanks for the findings, no one noticed that post was 1.2 year old and the only you who noticed. Thanks again, corrected in the write up..:)

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.