The touch
Linux command is useful for patrons who need to create, regulate, or substitute document timestamps. Essentially, the command signifies that you’ll be able to “touch” a document, rising it if it doesn’t exist, or updating the get admission to and modification circumstances if it does. It’s a simple however difficult command that plays a very powerful place in document regulate.
While the touch
command is unique in its capacity, it often works in conjunction with directions like ls
for record data and chmod
for changing permissions. Execs similar to instrument administrators, developers, and data analysts find this command handy for various tasks like scripting, document team, and automation.
Learn the way to Use touch
1. Creating a New Empty File
Syntax: touch filename
Rationalization: Creates a brand spanking new empty document named “filename.”
Example: touch newfile.txt
The command creates a brand spanking new empty document named newfile.txt
.
2. Updating the Timestamp of an Provide File
Syntax: touch existingfile
Rationalization: Updates the get admission to and modification timestamps of existingfile
to the current time.
Example: touch myfile.txt
The command updates the timestamps of myfile.txt
.
3. Rising A couple of Empty Information
Syntax: touch file1 file2 file3
Rationalization: Creates a couple of new empty data.
Example: touch file1.txt file2.txt file3.txt
The command creates 3 new empty data named file1.txt
, file2.txt
, and file3.txt
.
4. The use of a Particular Timestamp
Syntax: touch -t TIMESTAMP filename
Rationalization: Devices the get admission to and modification timestamps of filename
to a decided on time.
Example: touch -t 202201011200 myfile.txt
The command gadgets the timestamps of myfile.txt
to 12:00 on January 1, 2022
5. Creating a File with a Particular Date
Syntax: touch -d DATE_STRING filename
Rationalization: Devices the get admission to and modification timestamps of filename
to a decided on date and time.
Example: touch -d '1 Jan 2022 12:00' myfile.txt
The command gadgets the timestamps of myfile.txt
to 12:00 on January 1, 2022.
6. Creating a File without Changing Timestamps if It Exists
Syntax: touch -c filename
Rationalization: Creates filename
if it does not exist, then again does not alternate timestamps if it does.
Example: touch -c existingfile.txt
If existingfile.txt
does not exist, the command creates it. If it does exist, the command does no longer the rest.
7. Creating a File with a Reference File’s Timestamps
Syntax: touch -r REF_FILE filename
Rationalization: Devices the get admission to and modification timestamps of “filename” to test those of a reference document “REF_FILE.”
Example: touch -r reference.txt myfile.txt
The command gadgets the timestamps of myfile.txt
” to test those of reference.txt
.
8. Creating a File and Suppressing Error Messages
Syntax: touch -f filename
Rationalization: Creates filename
and suppresses most error messages.
Example: touch -f myfile.txt
The command creates myfile.txt
and suppresses most error messages.
Additional Linux directions:
List Operations | rmdir · cd · pwd |
File Operations | cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip |
File Gadget Operations | chown · mkfs |
Networking | ping · curl · wget · iptables |
Search and Text Processing | in finding · grep · sed · whatis |
Gadget Information and Keep an eye on | env · historical past · most sensible · who |
Client and Session Keep an eye on | display screen · su · sudo |
The put up Find out how to Use the ‘contact’ Command in Linux seemed first on Hongkiat.
Supply: https://www.hongkiat.com/blog/linux-command-touch/
Contents
- 0.0.1 Learn the way to Use touch
- 0.0.1.1 1. Creating a New Empty File
- 0.0.1.2 2. Updating the Timestamp of an Provide File
- 0.0.1.3 3. Rising A couple of Empty Information
- 0.0.1.4 4. The use of a Particular Timestamp
- 0.0.1.5 5. Creating a File with a Particular Date
- 0.0.1.6 6. Creating a File without Changing Timestamps if It Exists
- 0.0.1.7 7. Creating a File with a Reference File’s Timestamps
- 0.0.1.8 8. Creating a File and Suppressing Error Messages
- 0.0.1.9 Additional Linux directions:
- 0.0.1 Learn the way to Use touch
- 0.1 Related posts:
- 1 How you can Behavior an Go out Interview: 7 Most sensible Questions [Form Template]
- 2 12 Techniques to Offer protection to Content material in WordPress (Final Information)
- 3 How To Create the Best possible Sticky Header for Your Web site With WordPress
0 Comments