Support > About cybersecurity > Common uses of the Linux Touch command
Common uses of the Linux Touch command
Time : 2025-02-19 16:01:26
Edit : Jtti

Each file in Linux is associated with a timestamp, and each file stores information about when it was last accessed, when it was modified, and when it was changed. The file event stamp is automatically updated when a new file is created or an existing file is accessed or modified. The following is a practical example of the Linux touch command, a standard Unix/Linux operating system program used to create, change, and modify file timestamps.

Touch Specifies the touch command options

a Used to change the access time.

c If the file does not exist, it is not created.

d Update access and change time.

r only changes the modification time. m Use file access and modify time.

t Create the file at the specified time.

Create a single empty file using touch

For example, we need to use the touch command to create an empty file named shee1:

# touch shee1

Create multiple empty files using touch

Or we want to create multiple single files, for example, create three files and name them sheet1, sheet2, and sheet3.

# touch sheet1 sheet2 sheet3

Change file access and modification times

When we need to change or update the last access and modification time of a file named sheet1, when the sheet1 file does not exist and need to create a new file with the same name, we can use the following command:

# touch -a sheet1

The find and Is commands are also used in popular Linux commands to find and list files using timestamps.

Avoid creating new files in the touch command

When the file sheet does not exist, you can avoid creating a new file with the c option:

# touch -c sheet

If you want to change the modification time of the sheet file, m will only update the last modification time of the file and not the access time:

# touch -m sheet

If you want to explicitly set access and modification times

You can set a specific time with the c and t options:

# touch -c -t YYDDHHMM sheet

For example, the following command sets the access and modification date and time of the file sheet to 17:30 on February 19 (17:30 PM) in the current year (2025).

# touch -c -t 02191730 sheet

You can verify the access and modification time of the file sheet with the ls -l command:

# ls -l

The touch command with the -r option updates the timestamp of the file meena with the timestamp of the sheet file. Therefore, both files have the same timestamp.

# touch -r sheet meena

To create a file with a specified time other than the current time, the format should be

# touch -t YYMMDDHHMM.SS sheet

For example, the following touch command with the -t option will give the sheet file a timestamp of 18:30:55 PM on February 10, 2025.

# touch-t 202502101830.55 sheet

Relevant contents

Procedure for installing Python PIP on Windows Streaming platforms migrate from client-side to server-side adaptive bitrate streaming The impact of artificial intelligence on power consumption in data centers High-defense CDN acceleration and DDoS attack defense Artificial intelligence is reshaping the data center, transforming everything from infrastructure to sustainability CDN acceleration principle and CDN acceleration technology Taiwan BGP server room rental IEPL dedicated line IPLC dedicated line Use and dynamic configuration of environment variables in Docker Compose Methods for disabling or locking package updates in Yum and DNF
Go back

24/7/365 support.We work when you work

Support