Linux Basic Commands
13. touch
touch Command in Linux
The touch command is used to:
-
Create an empty file.
-
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 |
|---|---|
|
|
Create a new empty file |
|
|
Create multiple files |
|
|
Update modified time of existing file |
|
|
Set custom timestamp |
|
|
Update time only if file exists |
Try with Linux Practice