Top 10 useful Touch command on Linux

Top 10 useful Touch command on Linux.

Just like Windows, iOS, and Mac OS, Linux is an operating system. It is one of the most popular platforms. Linux is also distributed under an open source license.Linux was designed to be similar to UNIX, but has evolved to run on a wide variety of hardware from phones to supercomputers. Every Linux-based OS involves the Linux kernel which manages hardware resources and a set of software packages that make up the rest of the operating system.

Linux Touch commands

The linux touch commands are used to modify the access/modification timestamps of files. By using the commands you can easily create an empty file.


In this article we are going tell you how the touch commands are used for modifying timestamps or creating files.

1. Create a blank file

$ touch demo.txt

The above syntax allow you to simply create a blank file.If the file already exists then the access time will be updated.

2. Create multiple files

$ touch demo1.txt demo2.txt demo3.txt

This command allow you to create multiple files.

3. Create large number of files

$ touch {A..Z}
$ touch {1..10}
$ touch {1..100}.txt

The above commands will be used for creating large number of files.
First one will be used to create files with names A to Z
Second one will be used to create files with names 1 to 10
Third one will be used to create files with names 1 to 100 with .txt extension

4. Avoid creating new files

$ touch -c demo.txt

This will be used if you don’t want to create file but just want to update access time of existing file. Here demo.txt not created but the access time will update.

5. Change file access time

$ touch -a demo.txt

To change only access time of a file use the ‘-a’ option with the file name.

6. Change the modified time

$ touch -m demo.txt
$ touch -m *.txt

First command: Use the ‘-m’ option to change the modified time of the demo file.
Second command: To change the modify time of multiple files using wildcard.

7. Change access and modification time together

$ touch -am demo.txt

Use the a and m option together to modify both access and modification time

8. Set a specific access/modify time instead of current time

$ touch -c -t 1603051055 demo.txt
$ touch -c -t 201603051915 demo.txt

To set the access/modify time to a specific datetime use the t option and specify the datetime in format [[CC]YY]MMDDhhmm[.ss]

If you not enter the c option then a new file will be created with the given datetime if it does not exist.

9. Use the timestamp of another file as reference

$ touch -r ref.txt demo.txt

The above command will set the access/modify time of demo.txt to that of ref.txt

10. Specify datetime as a string

$ touch -c -d ’10 Apr’ demo.txt

Apart from the t option, there is another option ‘-d’ which accepts datetime in general human readable formats.

The above command provides the date only. The time is automatically set to 00:00

Leave a Comment