touch Linux command
The Linux touch command is used to create empty files with specified timestamps or update the accessed, modified, or changed times of a file. It is a versatile command that can be used for various purposes such as creating placeholder files, changing file timestamps, and triggering certain actions based on file modification times. The touch command is a powerful tool for managing files and directories efficiently in a Linux environment.
touch Syntax:
touch [option] [file]
Options:
Option | Description |
---|---|
-a | Update the access time |
-c | Do not create a new file |
-m | Update the modification time |
-r | Use the access and modification times of another file |
-t | Use a specific timestamp |
Parameters:
Parameter | Description |
---|---|
file | Name of the file to be created or updated |
touch bash Examples:
Create an Empty File
touch example.txt
Creates a new empty file named “example.txt”.
Update the Timestamp of a File
touch -m example.txt
Updates the modification timestamp of the file “example.txt”.
Create Multiple Empty Files
touch file1.txt file2.txt file3.txt
Creates three empty files named file1.txt, file2.txt, and file3.txt.
Update Access and Modification Time of a File
touch -a -m example.txt
Updates both the access and modification times of the file “example.txt”.
Create a File with Specific Timestamp
touch -t 202201011200 example.txt
Creates a file “example.txt” with a specific timestamp of January 1st, 2022, 12:00 PM.
Create a File with a Future Timestamp
touch -t 202301011200 example.txt
Creates a file “example.txt” with a future timestamp of January 1st, 2023, 12:00 PM.
touch Command Help Center:
How do I use touch in Linux?
To use the touch command in Linux, execute the following command:
touch filename.txt
What is the purpose of the touch command in Linux?
The touch command in Linux is used to update the access and modification timestamps of a file. It can also be used to create a new empty file if the specified file does not already exist.
touch filename.txt
How can I update the timestamps of a file using touch?
To update the timestamps of a file to the current time, you can use the touch command with the file name as an argument:
touch filename.txt
Can I create multiple files at once with the touch command?
Yes, you can create multiple files at once using the touch command by specifying multiple file names as arguments:
touch file1.txt file2.txt file3.txt
How can I change the access and modification timestamps to a specific date/time using touch?
To change the timestamps of a file to a specific date and time, you can use the -t option followed by a specific timestamp in the format [[CC]YY]MMDDhhmm[.ss]:
touch -t 202112311200.00 filename.txt
Is there a way to suppress error messages when using touch in Linux?
Yes, you can suppress error messages by using the -c option with the touch command. This will prevent error messages from being displayed if a file does not exist.
touch -c non_existent_file.txt
How can I update the timestamp of a file without creating a new file if it does not exist?
If you want to update the timestamp of a file without creating a new file if it does not exist, you can use the -m option with the touch command:
touch -m filename.txt
Can I use touch with symbolic links in Linux?
Yes, you can use touch with symbolic links in Linux. By default, touch will update the timestamps of the symbolic link itself, not the target file that the link points to.
touch symlink_name
Applications of the touch command
- Create an empty file
- Update the access and modification timestamps of a file
- Change the timestamps of a file to a specific date and time
- Create a new file with specific content and timestamp
- Create multiple files at once using touch with file name patterns