In Linux distributions, each document that is created on the system is provided with some timestamps. Each document must store the information about the last access time, the last modification time, and the last modification time. So all the timestamp information is updated when you create, access or modify a file.
The "touch" command is a program used in Linux operating systems to create, edit, and modify timestamps of a particular file. In this article, we will examine some common examples of the Linux touch command in Rocky Linux 8
To use touch command on Rocky Linux, you need to open the terminal window to press ‘Ctrl + Alt + t’.
The touch command is used to create a new empty file. To create a new file you will execute the following command on the terminal:
$touch testfile
The touch command is also used to create more than one file. The following command is used to create multiple files:
$touch testfile1 testfile2 testfile3
You can update or change the last modification and access time of a file. The -a option is used with touch command as follows.
$ touch -a workplace
The above-mentioned command changes the date and current time on a file. If the ‘workplace’ file does not exist, then, in this case, a new file will create with a similar name.
The touch command with -c option is used to avoid creating a new file. For example, an empty file with ‘testdata’ name will not create on the system, if the file doesn’t exist. Type the following command on the terminal:
$ touch -c testdata
If you want to change only the modification time instead of the last access time of ‘testfile’ then you will use touch command with -m option. Use the following command on the terminal to perform this action:
$ touch -m testfile
You can explicitly change the modification and access time of a file. The basic format of this command is given below:
$ touch -c -t YYDDHHMM testfile
For example, if you want to set the modification date and access time to a file ‘testfile’ as 17:30 (17:30 p.m.) 2 January of the current year (2022).
$touch -c -t 01021730 testfile
To verify this command, use the following command:
$ ls -l
The touch command with -r option is used to update the timestamp of ‘testfile1’ and replace it with the timestamp of ‘testfile’ file. Both files will hold the same timestamp:
$ touch -r testfile testfile1
If you want to create a file with a specified time instead of assigning the current time then you will use the following format of the command:
$ touch -t YYMMDDHHMM.SS filename
For example, if you want to use touch command with option -t will give the ‘testfile’ file a timestamp of 17:30:40 p.m. on January 03, 2020.
$ touch -t 202001031730.40 testfile
Some useful touch command options with their purpose are given below:
In this article, you learned about different uses of the touch command in Rocky Linux 8. You also learned several commands that will be useful to you in the future. I hope you enjoyed this article and learned new things.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…