How to Modify Date and Timestamps Using touch on CentOS

This post will guide you on how to modify date and time stamps using “touch” command. The touch command is easy to use and there are two reason to use it.

1. To create a file.
2. To update a file’s modification date.

The touch command is part file utilities package and has several options.

How to modify date and timestamps using touch ?
Touch can update a file’s date and time. you can even use touch to change a file’s date or time to the past or the future, for example:

READ  How to Add Linux Swap Space on CentOS 6 VPS

a)Change date to past time:

    [root@server ~]# touch -t 0101141400 newtestfile1
    [root@server ~]# ls -l --full-time newtestfile1
    -rw-r--r-- 1 root root 0 2001-01-14 14:00:00.000000000 +0800 newtestfile1
    

Description:
The –full-time option and long format listing of the ls command show that the file newtestfile1 now has a timestamp of (2.00PM, 14 January 2001)

b)Change date to future time:

    [root@server ~]# touch -t 1212261400 newtestfile1
    [root@server ~]# ls -l --full-time newtestfile1
    -rw-r--r-- 1 root root 0 2012-12-26 14:00:00.000000000 +0800 newtestfile1
    

Description:
The –full-time option and long format listing of the ls command show that the file newtestfile1 now has a timestamp of (2.00PM, 26 December 2012)

Leave a Reply

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