Linux/Unix: How to manipulate or change the last modified/accessed time of a file using touch command?

Assume there’s a file @ /home/user/testmsg.txt

If you want to change the file timestamp to 09/20/2011 08:30 using touch command, here’s how you can do it:

# Only change the last accessed time
touch -t -a 20110920083000 /home/user/testmsg.txt

# Only change the last modified time
touch -t -m 20110920083000 /home/user/testmsg.txt

# Change both the times - modified and accessed times
touch -t 20110920083000 /home/user/testmsg.txt

From Wikipedia,

touch is a standard Unix program used to change a file‘s access and modification timestamps. It is also used to create a new empty file.


One comment

  1. Thanks for this good summary. Is this not a security issue. How can I search the file system to see what files have changed if a hacker can modify the PHP files and simply touch the date back to the original value?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: