The contact Linux command comes in handy for customers who wish to create, alter, or replace record timestamps. Necessarily, the command means that you can “contact” a record, growing it if it doesn’t exist, or updating the get entry to and amendment instances if it does. It’s a easy but tough command that performs an important position in record control.

Whilst the contact command is exclusive in its capability, it incessantly works together with instructions like ls for list information and chmod for converting permissions. Pros comparable to device directors, builders, and knowledge analysts in finding this command at hand for more than a few duties like scripting, record group, and automation.

Find out how to Use contact

1. Making a New Empty Report

Syntax: contact filename

Clarification: Creates a brand new empty record named “filename.”

Instance: contact newfile.txt

The command creates a brand new empty record named newfile.txt.

2. Updating the Timestamp of an Present Report

Syntax: contact existingfile

Clarification: Updates the get entry to and amendment timestamps of existingfile to the present time.

Instance: contact myfile.txt

The command updates the timestamps of myfile.txt.

3. Growing More than one Empty Recordsdata

Syntax: contact file1 file2 file3

Clarification: Creates more than one new empty information.

Instance: contact file1.txt file2.txt file3.txt

The command creates 3 new empty information named file1.txt, file2.txt, and file3.txt.

4. The usage of a Explicit Timestamp

Syntax: contact -t TIMESTAMP filename

Clarification: Units the get entry to and amendment timestamps of filename to a selected time.

Instance: contact -t 202201011200 myfile.txt

The command units the timestamps of myfile.txt to twelve:00 on January 1, 2022

5. Making a Report with a Explicit Date

Syntax: contact -d DATE_STRING filename

Clarification: Units the get entry to and amendment timestamps of filename to a selected date and time.

Instance: contact -d '1 Jan 2022 12:00' myfile.txt

The command units the timestamps of myfile.txt to twelve:00 on January 1, 2022.

6. Making a Report with out Converting Timestamps if It Exists

Syntax: contact -c filename

Clarification: Creates filename if it does now not exist, however does now not exchange timestamps if it does.

Instance: contact -c existingfile.txt

If existingfile.txt does now not exist, the command creates it. If it does exist, the command does not anything.

7. Making a Report with a Reference Report’s Timestamps

Syntax: contact -r REF_FILE filename

Clarification: Units the get entry to and amendment timestamps of “filename” to check the ones of a reference record “REF_FILE.”

Instance: contact -r reference.txt myfile.txt

The command units the timestamps of myfile.txt” to check the ones of reference.txt.

8. Making a Report and Suppressing Error Messages

Syntax: contact -f filename

Clarification: Creates filename and suppresses maximum error messages.

Instance: contact -f myfile.txt

The command creates myfile.txt and suppresses maximum error messages.

Extra Linux instructions:
Listing Operations rmdir · cd · pwd
Report Operations cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip
Report Machine Operations chown · mkfs
Networking ping · curl · wget · iptables
Seek and Textual content Processing in finding · grep · sed · whatis
Machine Data and Control env · historical past · most sensible · who
Consumer and Consultation Control display screen · su · sudo

The submit Find out how to Use the ‘contact’ Command in Linux gave the impression first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-touch/

[ continue ]