Linux – touch Command

The touch command is used to create empty files or update the access and modification timestamps of existing files. This command is useful for quickly creating new files or for updating the timestamps of files without changing their content.



Tutorials dojo strip

Initial Example

Using touch to create a new empty file called newfile.txt:

touch newfile.txt




TOUCH Parameters

ParameterDescription
-aUpdate only the access time of the file
-c, --no-createDo not create any files if they do not exist
-d, --date=STRINGUse the specified date and time instead of the current time
-fIgnored; included for compatibility
-h, --no-dereferenceAffect the symbolic link itself, rather than the file it points to
-mUpdate only the modification time of the file
-r, --reference=FILEUse the times of the specified file instead of the current time
-t [[CC]YY]MMDDhhmm[.ss]Set the specified time using the given format
--time=WORDSpecify which time to change: access time (-a) or modification time (-m)
--helpDisplay help information and exit
--versionShow version information and exit




Examples

1. Create an Empty File

To create a single empty file:

touch filename.txt

2. Create Multiple Empty Files

To create multiple empty files at once, specify their names separated by spaces:

touch file1.txt file2.txt file3.txt

3. Update Timestamps of Existing Files

To update the access and modification timestamps of an existing file without changing its content:

touch existingfile.txt

4. Set a Specific Timestamp

To set a specific timestamp for a file, use the -t option followed by the timestamp in the format [[CC]YY]MMDDhhmm[.ss]:

touch -t 202404151230.00 file.txt

5. Change Only the Access Time

To change only the access time of a file, use the -a option:

touch -a file.txt

6. Change Only the Modification Time

To change only the modification time of a file, use the -m option:

touch -m file.txt




Linux Playground

Scroll to Top