Home  >  Article  >  Operation and Maintenance  >  What is the use of linux touch command

What is the use of linux touch command

青灯夜游
青灯夜游Original
2021-04-15 16:09:4817987browse

In Linux, the touch command is used to modify the time attributes of a file or directory, including access time and change time. The syntax format is "touch [option][file or directory...]". When using the touch command, if the specified file does not exist, the system will create a new blank file.

What is the use of linux touch command

#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.

Detailed explanation of touch command

1. Command function

Linux touch command is used to modify files Or the time attributes of the directory, including access time and change time.

2. Syntax format

touch [option][文件或目录…]

option description:

  • a Change the file reading time record.

  • m Change the modification time record of the file.

  • c If the destination file does not exist, a new file will not be created. Same effect as --no-create.

  • f Not used, reserved for compatibility with other unix systems.

  • r Use the time record of the reference file, which has the same effect as --file.

  • d To set the time and date, you can use various formats.

  • t Set the time record of the file, the format is the same as the date command.

  • --no-create will not create a new file.

  • --help lists the command format.

  • --version List version information.

3. Parameter option description

  • No option: If the file does not exist, create a new empty file. Access time, modify time and change time are all the current time; if the file exists, all three timestamps will be modified to the current time

    What is the use of linux touch command
  • ##-a: Only modify the access time of the file

    What is the use of linux touch command
    Note: After the access time is modified, the change time is also modified (because the status has changed).
  • -m: Only modify the modify time of the file

    What is the use of linux touch command
    Note: After the modify time is modified, the change time is also changed Modified (because the state has changed).
  • -c: Do not create non-existing files (when multiple files are operated after touch, non-existing files will not be created)

  • -d: Use the specified date and time instead of the current time. Various formats can be used.

    What is the use of linux touch command
  • -t: Modify the time to the date specified by the parameter, such as: 07081556 represents 15:56 on July 8th

    What is the use of linux touch command

    Note: The change time has changed and became the current time.

    The time format of this option is [[CC]YY]MMDDhhmm[.ss]

    What is the use of linux touch command
  • -r file : Use the timestamp of the specified file (access, modify) to update the timestamp of the file (access, modify)

    What is the use of linux touch command
    Note: the change time has changed and became the current time.
Note: When using the command "touch", if the specified file does not exist, a new blank file will be created. For example, use this command to create a blank file "file" in the current directory and enter the following command:

$ touch file            #创建一个名为“file”的新的空白文件

Related recommendations: "

Linux Video Tutorial"

The above is the detailed content of What is the use of linux touch command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:linux open port commandNext article:linux open port command