The touch is the command in Linux and Unix-like operating systems. The primary use of the touch command is to create, change and modify time stamps of a file in Linux and Unix-like operating systems. Generally, there are two different commands to create a file in the Linux system.
- If you want to create a file with content, then you can use the cat command.
- If you want to create an empty file, then you can touch command
When we create any file using the touch command is empty. This command is handy when you don’t have data to store at the time of file creation. So, You can create single or multiple files at a time using this command,
Creating a single file with the touch command
So, you can create single or multiple files at a time using this command,
For Example: I’m creating a single file with the name Amit,
Creating multiple files with the touch command
So, I’m going to create multiple files at a time with the file name, Sahil, Manish, Rahul
touch Sahil Manish Rahul
Changing the access time of the file
If you want to change the access time, then you can use the -a option along with touch command. So you can find the below command useful for that.
touch -a file_name
touch -a Amit
Here, Amit is the name of the file, and with the help of -a, we can change the access time. As a result, you can see in the below picture.
To check the file, If it is created or not. You can use -c with touch command
touch -c file_name
touch -c sonu
Note: If there is no such file with the name of sonu, It will not create any file. So, you can see the result in the below picture.
To update access and modification time
If you want to update the access and modification time, then you can use argument -c and -d with touch command,
touch -c -d file_name
touch -c -d '06 may' amit
So, you can see in the below picture, the access and modification time has been changed,
To change the modification time only, you can use -m with touch command.
touch -m file_name
touch -m Rahul
here, Rahul is the file name. As a result, you can see in the picture,
To create a file with a specific time
touch -t YYMMDDHHMM file_name
touch -t 202004180600 Sudarshan
In the above example, we are creating a file for April 18, 2020, at 06:00 with the name of Sudarsan. You can see in the below picture,
In this article, you learned about touch command in Linux, and it is a little hard to use for further use, but it is easy if you are creating a file only. So, I hope, you understand. But if you have any questions, you can ask in the comment section.
Also, you can read about the below topics.