User Tools

Site Tools


unix_commands:touch

The touch command in Linux and Unix-like systems is used to create new empty files or update the timestamps of existing files.

Here is the basic syntax for the touch command:

touch [options] file

file is the name of the file you want to create or update. Here are some examples of the touch command in action:

1. To create a new empty file called “file1.txt” in the current directory:

$ touch file1.txt

2. To create multiple files at once

$ touch file1.txt file2.txt file3.txt

3. To update the timestamp of an existing file called “file1.txt” in the current directory:

$ touch file1.txt

4. To change the timestamp of a file to a specific time

$ touch -t 202212151600 file1.txt

Note: The -t option is used to specify the time in the format of YYMMDDHHMM, in this case the time is set to December 15, 2022 at 4:00 PM Hint: To read the “202212151600” figure, split it like this: “2022-12-15 at 16:00”

5. To change the timestamp of a file to the current time

$ touch -r file2.txt file1.txt

Note: The -r option is used to change the timestamp of file1.txt to the timestamp of file2.txt

The touch command is useful when you need to create new empty files or update the timestamps of existing files. It can also be used to reset the access time of a file to the current time, which is useful when you want to prevent a file from being deleted by a script that is cleaning up old files.

unix_commands/touch.txt · Last modified: 2023/01/17 00:25 by admin

CIFNet is a leading hosting solution provider, offering a wide range of services including IP bandwidth, co-location, VMware and KVM hosting.
Host Your Site with CIFNet!