Easy Tutorial
❮ Linux Comm Zip Linux Comm Crontab ❯

Linux touch Command

Linux Command Manual

The Linux touch command is used to modify the time attributes of files or directories, including access and modification times. If the file does not exist, the system will create a new file.

The ls -l command can display the time records of the file.

Syntax

touch [-acfm][-d<date-time>][-r<reference-file-or-directory>] [-t<date-time>][--help][--version][file-or-directory…]

Example

Use the "touch" command to modify the time attributes of the file "testfile" to the current system time, enter the following command:

$ touch testfile                # Modify the file's time attributes

First, use the ls command to view the attributes of the testfile file, as shown below:

$ ls -l testfile                # View the file's time attributes  
# Original file modification time was 16:09  
-rw-r--r-- 1 hdd hdd 55 2011-08-22 16:09 testfile

After executing the "touch" command to modify the file attributes and then viewing the file's time attributes again, as shown below:

$ touch testfile                # Modify the file's time attributes to the current system time  
$ ls -l testfile                # View the file's time attributes  
# Modified file's time attributes to the current system time  
-rw-r--r-- 1 hdd hdd 55 2011-08-22 19:53 testfile

When using the "touch" command, if the specified file does not exist, a new blank file will be created. For example, to create a new blank file named "file" in the current directory, enter the following command:

$ touch file            # Create a new blank file named "file"

Linux Command Manual

❮ Linux Comm Zip Linux Comm Crontab ❯