touch's Examples

Touch command Syntax to create a new file: You can create a single file at a time using touch command

touch file_name

Touch command to create multiple files

touch File1_name File2_name File3_name

touch -a: This command is used to change access time only. To change or update the last access or modification times of a file touch -a command is used.

touch -a fileName

touch -c : This command is used to check whether a file is created or not. If not created then don’t create it. This command avoids creating files.

touch -c fileName

touch -c-d : This is used to update access and modification time.

touch -c-d fileName

touch -m : This is used to change the modification time only. It only updates last modification time.

touch -m fileName

touch -r : This command is used to use the timestamp of another file. Here Doc2 file is updated with the time stamp of File 1.

touch -r second_file_name first_file_name

touch -t : This is used to create a file using a specified time.

touch -t YYMMDDHHMM fileName

Create an Empty File using touch

$ touch tgs.txt

use -c option to avoid creating new files. If you use -c option, and if a file doesn’t exists, touch will not create the file.

$ touch -c a.txt

create more than 1 files from a single touch command. The following example will create 4 files named a, b, c, and d.

$ touch a b c d

We can change the access time of a file using -a option.

$ touch -a tgs.txt

Change File’s Modification Time using -m

$ touch -m *.o

Copy the Time-stamp from Another File using -r

$ touch a.txt -r tgs.txt

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us