Get the App
SLTechnology News&Howtos  ›  Servers  › 

Create a file using the touch command of linux

Shulou Source: shulou.com Published: 2022-06-02 12:42:15 10月31日 Update

Editor to share with you the use of linux touch command to create files, I believe that most people do not know much, so share this article for you to learn, I hope you will learn a lot after reading this article, let's go to learn the method!

The touch command has two functions: one is to create a new empty file, and the other is to change the timestamp attribute of an existing file.

The touch command updates the access time and modification time of the specified file based on the current system time. If the file does not exist, a new empty file will be created unless the "- c" or "- h" options are specified.

Note: when modifying the time attribute of a file, the user must be the owner of the file or have access to write to the file.

Syntax format: touch [parameters] [file]

Commonly used parameters: coach

-a change the read time record of the file-m change the modification time record of the file-r use the time record of the reference file, the effect is the same as-- file-c does not create a new file-d set the time and date, you can use a variety of different formats-t to set the time record of the file, the format is the same as the date command-- no-create does not create new files-- help displays help information

-- version lists version messages

Reference example

Create an empty file:

[root@linuxcool ~] # touch file.txt

Create files in bulk:

[root@linuxcool ~] # touch file {1.. 5} .txt

[root@linuxcool ~] # ls

File1.txt file2.txt file3.txt file4.txt file5.txt

Modify the access (access) time of the file:

[root@linuxcool ~] # stat file.txt

File: file.txt

Size: 0 Blocks: 0 IO Block: 512 regular empty file

Device: 2h/2d Inode: 87538717757135273 Links: 1

Access: (0666) Uid: (1000 / root) Gid: (1000 / root)

Access: 2019-04-07 00 purl 25 purl 34.729216500 + 0800

Modify: 2019-04-07 00 purl 25 purl 34.729216500 + 0800

Change: 2019-04-07 00 purl 25 purl 34.729216500 + 0800

Birth:-

[root@linuxcool] # touch-a file.txt

[root@linuxcool ~] # stat file.txt

File: file.txt

Size: 0 Blocks: 0 IO Block: 512 regular empty file

Device: 2h/2d Inode: 87538717757135273 Links: 1

Access: (0666) Uid: (1000 / root) Gid: (1000 / root)

Access: 2019-04-07 0026 Vera 13.004116000 + 0800

Modify: 2019-04-07 00 purl 25 purl 34.729216500 + 0800

Change: 2019-04-07 0026 Vera 13.004116000 + 0800

Birth:-the above is all the contents of the file created using linux's touch command, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: File time command format file learning content parameters properties reference help different same not so two creative information function most learning methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Xiaomi Shulou Tech Info Shulou Information