The touch command in Linux is used to create empty files or update the access and modification timestamps of existing files. It's a simple yet versatile command useful in various scenarios, especially in scripting and file management.
touch [options] file...
touch filename.txt
This command creates an empty file named filename.txt in the current directory.
touch existingfile.txt
If existingfile.txt already exists, the command updates its access and modification timestamps to the current time without altering the file's content.
touch file1.txt file2.txt file3.txt
This command creates multiple empty files (file1.txt, file2.txt, and file3.txt) simultaneously.
touch -a filename.txt
This option updates only the access time of the file.
touch -m filename.txt
This option updates only the modification time of the file.
touch -c filename.txt
This option prevents touch from creating a new file if it does not exist. It only updates the timestamps of existing files.
touch -t 202406231200.00 filename.txt
This option sets the access and modification times to the specified time. For example, 202406231200.00 sets the time to June 23, 2024, at 12:00:00 PM.
touch -r referencefile.txt filename.txt
This option sets the timestamps of filename.txt to match those of referencefile.txt.