touch Command.
The touch
command is simple yet powerful.
Its primary use is to create empty files and update the timestamps of existing files. Using touch
with no option changes a file's access and modification times to the current time —and NO!!!, the touch command does not replace or overwrite the contents of an existing file. Instead, it updates the file’s access and modification timestamps to the current time. If the file already exists, its contents remain unchanged.
🎧
Here are some six (6) common uses:
1. Create a new Empty File
$ touch SNUBmonkey.txt
If SNUBmonkey.txt does not already exist in the current directory, this command will create an empty file with that name.
2. Resetting a File’s Timestamp
$ touch SNUBmonkey.txt
If SNUBmonkey.txt exists, the command will update the file's access and modify timestamps to the current time, without altering its content, and —No, the command will not remove or delete the file.
3. Create Multiple Files at once
$ touch SNUBmonkey-0.txt SNUBmonkey-1.tx SNUBmonkey-2.tx SNUBmonkey-3.tx
This command is useful when you need to create multiple files at once.
4. Set a Specific Timestamp (use -t
option)
$ touch -t 202408180812.41 SNUBmonkey.txt
This sets the timestamp to August 18, 2024, 08:12:41.
5. Change the Timestamp to a Specific date (use -d
option)
$ touch -d "2024-02-09 21:30:55" SNUBmonkey.txt
This sets the timestamp to February 09, 2024, 21:30:55.
6. Synchronizing Timestamps Between Files (use -r
option)
$ touch -r SNUB.txt monkey.txt
The monkey.txt will have the same last access and modification times as SNUB.txt.
The touch
command is a flexible and essential tool in Linux, offering a simple yet powerful way to manage files. Creating new files, updating timestamps, or synchronizing file modifications, touch
provides an efficient method for handling these tasks without altering file content.
We hope those tips were helpful!