In this blog we have elaborated the usage of a touch command in Ubuntu 22.04 by demonstrating some basic and advanced examples of this command. Without any further ado let’s get started.
Here are some basic examples of the touch command in Ubuntu 22.04 that explain the uses of this command.
One of the basic usages of the touch command is generating new files. The command written below is the simplest and fastest way to create a file with the touch command. This method is used most often by system administrators.
To see the new file generated use the ‘ls’ command as indicated in the output.
Output
A new empty file has been generated.
Another usage or one may consider this an advantage of the touch command is that you can generate numerous files with just one command line.
Output
Here we have generated three files.
For the purpose of evaluating the modification date and time of a file, you can use the stat command:
Output
Now let’s apply the touch command. Running the touch command on that particular file will update and display the modification date and time of the file making it the same as the date and time of the system.
Output
Modification date and time of the file are equal to that of the system.
Although by default the touch command will make the modification time of the file equal to that of the system as mentioned already. However, use the -t option to perform it manually.
Now you can validate this change using the stat command.
Output
The access time is equal to modification time.
Using the -a option along with the touch command will allow you to alter the access time of a file.
Output
The access time that was altered in the previous example has now been updated.
In order to do this use the -m option to alter the modification time of a file.
Output
The modification time which we changed previously has now been updated.
Here we have demonstrated some advanced usages of the touch command in Ubuntu 22.04.
When you use the -r option along with the touch command it basically references a particular file and equals the modification time of a file equal to that of the file you referenced.
Output
The modification time of doc1 is equal to sample.txt
Using the -c or a –no-create option with the touch command prevents the creation of new files that do not already exist when updating the modification time of a file.
Output
No new file is generated.
For the purpose of updating the modification time of a link instead of a file use the -h or a –no-dereference option.
Output
The modification time of a link has been updated.
Touch command in Ubuntu 22.04 serves various purposes such as generating an empty file, or multiple files all at once. Moreover, this can be used to evaluate the modification time or access time of files. You can also update these timestamps of a file according to your desire using the touch command. These are some basic usages of this command, whereas the advanced usages consist of making the timestamp of one file equal to another, updating the modification time of a link, etc.
Welcome to the Ubuntu Weekly Newsletter, Issue 868 for the week of November 24 –…
Industrial cybersecurity is on every CISO’s mind as manufacturers strive to integrate their IT and…
Dec 01,2024 Xfce 4.20 Pre2 Released Dear Xfce community, I am happy to announce the…
When you buy a Linux VPS with Bitcoin, you are getting a private virtual server…
Anaconda is a package, dependency function, and environment management. As environment management for programming languages,…
In September we introduced Authd, a new authentication daemon for Ubuntu that allows direct integration…