...

Touch Command in Linux (or Unix | MacOS) in 2 Minutes

Rate this post

What is the touch command in Linux(Unix)?

The touch command in Linux is used to create an empty file. It is also used to update the “last modified timestamp” of a file.
E.g

touch file1.txt

Prerequisites

Syntax

touch filename

To create multiple files with a single touch command, use the below syntax

touch file1 file2 file3 .. filen
# or
touch file{1..10}.txt # this will create file1.txt to file10.txt in one go

Description

To know details of the touch command, please run man touch.

Major Use cases of Touch command

Apart from the 3 use cases mentioned above, the touch command can be used for the below use cases as well.

Update the access timestamp of a single file or multiple file

touch -a file1 file2..filen
# example
touch -a file1 file2 file3

Update the modified timestamp of a single file or multiple file

touch -t file1 file2..filen
# example
touch -t file1 file2 file3

Conclusion

In this short post, you learned about how to use the touch command for various use cases.

Enjoy the post!!

Spread the love

Leave a Comment

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.