13. touch

touch Command in Linux

The touch command is used to:

  1. Create an empty file.

  2. Update the timestamp of an existing file (access and modification time).


📌 Syntax:

touch filename

🔹 1. Create a New Empty File

touch myfile.txt

🟢 This creates an empty file named myfile.txt in the current directory.


🔹 2. Create Multiple Files at Once

touch file1.txt file2.txt file3.txt

🟢 This creates all three files in one command.


🔹 3. Update Timestamp of Existing File

touch existingfile.txt

🟢 If existingfile.txt already exists, touch will not delete it — it simply updates the last modified time to the current time.


🔹 4. Change Timestamp to Specific Time

touch -t 202507011200 myfile.txt

🟢 This sets the time to 1st July 2025, 12:00 PM.


🔹 5. Don’t Create New File (Only Update if Exists)

touch -c myfile.txt

🟢 If the file doesn’t exist, it does nothing.


Summary Table

Command

Description

touch newfile.txt

Create a new empty file

touch file1 file2 file3

Create multiple files

touch existing.txt

Update modified time of existing file

touch -t YYYYMMDDhhmm file

Set custom timestamp

touch -c file

Update time only if file exists

Try with Linux Practice