Linux Command - touch

touch - change file timestamps, or create a file if the file does not exist.

Syntax

1
touch [OPTION] FILE...

Description

Update the access and modification times of each FILE to the current time. You can choose to only change the access time and modification time individually.

A FILE argument that does not exist is created empty, unless -c or -h is supplied.

Option Description
-a change only the access time
-m change only the modification time
-c, –no-create do not create any files
-d, –date=STRING parse STRING and use it instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
-r, –reference=FILE use this file’s times instead of current time

Example

create file1 and file2

1
touch file1 file2

change file1’s time into file2’s time

1
touch -r file2 file1

set date time for a file

1
touch -t 201812312359.59 file1

set file1’s time to be Dec 31, 2018.

Reference