Touch Command Options
- -a, change the access time only
- -c, if the file does not exist, do not create it
- -d, update the access and modification times
- -m, change the modification time only
- -r, use the access and modification times of the file
- -t, creates a file using a specified time
1. How to Create an Empty File
The following touch command creates an empty (zero-byte) new file called sheena.
2. How to Create Multiple Files
By using the touch command, you can also create more than one single file. For example, the following command will create 3 files named, sheena, meena, and leena.
3. How to Change File Access and Modification Time
To change or update the last access and modification times of a file called leena, use the -a option as follows. The following command sets the current time and date on a file. If the leena file does not exist, it will create a new empty file with the name.
The most popular Linux commands such as the find command and ls command use timestamps for listing and finding files.
4. How to Avoid Creating New File
Using the -c option with the touch command avoids creating new files. For example, the following command will not create a file called leena if it does not exists.
5. How to Change File Modification Time
If you like to change the only modification time of a file called leena, then use the -m option with the touch command. Please note it will only update the last modification times (not the access times) of the file.
6. Explicitly Set the Access and Modification times
You can explicitly set the time using the -c and -t option with the touch command. The format would be as follows.
For example, the following command sets the access and modification date and time to a file leena as 17:30 (17:30 p.m.) December 10 of the current year (2020).
Next verify the access and modification time of file leena, with the ls -l command.
7. How to Use the time stamp of another File
The following touch command with the -r option, will update the time-stamp of file meena with the time-stamp of leena file. So, both the file holds the same time stamp.
8. Create a File using a specified time
If you would like to create a file with a specified time other than the current time, then the format should be.
For example, the below command touch command with -t option will give the tecmint file a time stamp of 18:30:55 p.m. on December 10, 2020.
We’ve almost covered all the options available in the touch command for more options use “man touch“. If we’ve still missed any options and you would like to include them in this list, please update us via the comment box.
No comments:
Post a Comment