modify_time

touch command is used to modify the timestamps of the file. Suppose, you want to modify the time stamp of the file top.txt, use the command as follows:

linux:~ # ls -l top.txt
-rw-r–r–  1 root root 9637 Apr  2 00:20 top.txt
linux:~ #
linux:~ # touch -t 201106062145 top.txt
linux:~ # ls -l top.txt
-rw-r–r–  1 root root 9637 Jun  6  2011 top.txt
linux:~ #

The “-t” option modifies the time stamp of the file and the format is YYYYMMDDHHMM.

If you want to change the modification time of the file to current time, use the touch command with “-m” option as demonstrated below:

linux:~ # ls -l top.txt
-rw-r–r–  1 root root 9637 Jun  6  2011 top.txt
linux:~ #
linux:~ # touch -m top.txt
linux:~ #
linux:~ # ls -l top.txt
-rw-r–r–  1 root root 9637 Apr  2 14:29 top.txt
linux:~ #

The time stamp is changed to current system date and time after touch command is run with ‘-m’ option.

Adnan Khurshid

Adnan Khurshid, the author of this article, has been working in a telecommunication sector since 2007. He has worked there as a VAS (Value Added Services) engineer and has excelled remarkably in the field. Working in this field has been his passion and he has always made efforts to keep himself up to date. Find more about him on LinkedIn

More Posts

Tags: , , ,

1 Comment on How to modify the timestamp of files in Linux

  1. Philip Hughes says:

    Hi Adnan,
    are you still posting on this website, is it still active…
    I have a solaris issue I was wondering if you could help me with?
    Its telecoms related and hoped you could help
    Drop me an email if you can help and I will tell you about the issue i’m having,
    Thanks
    Philip

Leave a Reply