touch
touch linux command cheatsheet by Thamizhiniyan C S
Introduction
The primary function of the touch
command is to modify a file's timestamp. While it is often used to create files, this is not its main purpose.
Syntax
touch [OPTION]... FILE...
Important Flags
Flag | Description |
---|---|
| change only the access time |
| do not create any files |
| parse STRING and use it instead of current time |
| (ignored) |
| affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) |
| change only the modification time |
| use this file's times instead of current time |
| use [[CC]YY]MMDDhhmm[.ss] instead of current time |
| change the specified time: WORD is access, atime, or use: equivalent to -a: WORD is modify or mtime: equivalent to -m |
| display this help and exit |
| output version information and exit |
Time Stamp Formats
Syntax: [[CC]YY]MMDDhhmm[.ss]
Format | Description |
---|---|
| the first two digits for a year |
| the last two digits for a year |
| the month |
| the day |
| the hour |
| the minutes |
| the seconds |
Examples
Command | Description |
---|---|
To create a emtpy file | |
To create multiple files at the same time. These files will be empty upon creation. | |
To create ten files with appended numbering | |
To create ten files with appended alphabets | |
To change a file's access time to the current timestamp. | |
To modify access time explicitly. | |
To change both modification and access times to the current timestamp. | |
Checks if a file is created; if not, it doesn’t create it. | |
Updates both access and modification times. | |
To change a file's modification time to the current timestamp. | |
To set modification time explicitly. | |
Changes the modification date only. | |
To set a file's timestamp based on another file's timestamp. | |
Uses the timestamp of another file. | |
Creates a file with a specified time. | |
To set a specific timestamp for an existing file. | |
To modify the timestamp of a symbolic link without affecting the referenced file. |
Last updated