What are other `touch` options?

QuestionsQuestions8 SkillsProBasic Files OperationsSep, 08 2025
0113

The touch command in Bash has several options that can enhance its functionality. Here are some common options:

1. -a:

Updates the access time of the file without changing its content or modification time.

touch -a file1.txt

2. -m:

Updates the modification time of the file without changing its access time.

touch -m file1.txt

3. -c:

Does not create a new file if it does not exist. It only updates the timestamps of existing files.

touch -c file1.txt

4. -d:

Allows you to specify a custom date and time for the timestamp. For example:

touch -d "2023-01-01 12:00" file1.txt

5. -r:

Uses the timestamp of another file to set the timestamp of the specified file.

touch -r reference.txt file1.txt

6. -t:

Sets the timestamp to a specific value in the format [[CC]YY]MMDDhhmm[.ss].

touch -t 202301011200 file1.txt

Encouragement for Further Learning:

To practice using the touch command and its options, consider exploring relevant labs on the LabEx platform.

If you have more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!