The Linux touch command is used to modify the time attribute of a file or directory, including the access time and change time. If the file does not exist, the system creates a new file.
Ls-l can display the time record of the file.
Syntax
Touch [-acfm] [-d <date and time>] [-r <reference file or directory>] [-t <date and time>] [-- help] [-- version] [file or directory…]
Parameter description:
A. Change the reading time record of the file.
M changes the modification time record of the file.
C if the target file does not exist, no new file will be created. The same effect as -- no-create.
F is not used. It is reserved for compatibility with other unix systems.
R uses the time record of the Reference file, which has the same effect as -- file.
D. Set the time and date in different formats.
T sets the time record of the file. The format is the same as that of the date command.
-- No-create does not create a new file.
-- Help lists the instruction formats.
-- Version: list version information.
Instance
Run the command "touch" to modify the time attribute of file "testfile" to the current system Time. Run the following command:
$ Touch testfile # Modify the time attribute of an object
First, use the ls command to view the attributes of the testfile file, as shown below:
$ Ls-l testfile # view the file's time attribute # The original file's modification time is-rw-r -- 1 hdd 55 testfile
Run the command "touch" to modify the file attributes and view the time attributes of the file again, as shown below:
$ Touch testfile # Modify the file Time attribute to the current system Time $ ls-l testfile # view the file Time attribute # The modified file Time attribute is the current system Time-rw-r -- r -- 1 hdd 55 testfile
When the command "touch" is used, if the specified file does not exist, a new blank file will be created. For example, in the current directory, use this command to create a blank file, and enter the following command:
$ Touch file # Create a new blank file named "file"