Focus on cloud service provider activities
Notes on website operation and maintenance

Detailed usage and cases of Linux touch command

The touch command is used in Linux systems to create empty files or update the access and modification time of files. The following is a detailed introduction and case study of the touch command:

Command format:

 Touch [options]<file path>

Common options:

 -a: Only the access time (atime) is updated. -c: If the file does not exist, a new file is not created. -m: Only the modification time (mtime) is updated. -D<time>: use the specified time instead of the current time.

Case:

1. Create an empty file:

 touch file.txt

This command will create an empty file named "file. txt" in the current directory. If the file already exists, it will update the access and modification time of the file to the current time.

2. Create multiple files in batch:

 touch file1.txt file2.txt file3.txt

This command will create empty files named "file1. txt", "file2. txt" and "file3. txt" in the current directory at the same time.

3. Update file access and modification time:

 touch -m file.txt

This command will only update the modification time (mtime) of the file "file. txt" without affecting its access time (atime).

4. Create a file at the specified time:

 touch -d "2023-11-07 10:30" file.txt

This command will create a file named "file. txt" in the current directory, and set its access and modification time to the specified time ("2023-11-07 10:30").

5. Use touch to batch modify file time:

 touch -d "2023-11-07" *.txt

This command will set the access and modification time of all files ending in ". txt" in the current directory to the specified date ("2023-11-07").

The touch command is very simple and practical. It can be used to create empty files, update file access and modification time, and batch modify file time.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Detailed usage and cases of Linux touch command


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge