Skip to content

Latest commit

 

History

History
58 lines (48 loc) · 1.72 KB

File metadata and controls

58 lines (48 loc) · 1.72 KB

touch

The touch command in Linux is used to create empty files or update the access and modification timestamps of existing files. It's a simple yet versatile command useful in various scenarios, especially in scripting and file management.

Syntax

touch [options] file...

Usage

Create an Empty File

touch filename.txt

This command creates an empty file named filename.txt in the current directory.

Update Timestamps of an Existing File

touch existingfile.txt

If existingfile.txt already exists, the command updates its access and modification timestamps to the current time without altering the file's content.

Create Multiple Files at Once

touch file1.txt file2.txt file3.txt

This command creates multiple empty files (file1.txt, file2.txt, and file3.txt) simultaneously.

Options

-a (Change Access Time Only)
touch -a filename.txt

This option updates only the access time of the file.

-m (Change Modification Time Only)
touch -m filename.txt

This option updates only the modification time of the file.

-c or --no-create (Do Not Create Any Files)
touch -c filename.txt

This option prevents touch from creating a new file if it does not exist. It only updates the timestamps of existing files.

-t [[CC]YY]MMDDhhmm[.ss] (Specify Time)
touch -t 202406231200.00 filename.txt

This option sets the access and modification times to the specified time. For example, 202406231200.00 sets the time to June 23, 2024, at 12:00:00 PM.

-r reference_file (Use Reference File's Time)
touch -r referencefile.txt filename.txt

This option sets the timestamps of filename.txt to match those of referencefile.txt.