Linux for Developers
/Beginner
touch
Definition
A command primarily used to create empty files. Its secondary (and original) purpose is to update the access and modification timestamps of an existing file.
Explain Like I'm New
The 'create a blank file' command. It instantly creates a file with zero text inside it.
Real World Example
You want to write a Python script. You type `touch script.py`. An empty file is instantly created, which you can now open in a code editor.
Common Use Cases
- •Creating blank configuration files
- •Triggering file watchers by updating timestamps
Crucial Command Flags
| Flag / Option | Description |
|---|---|
| -c | No create. Do not create any files if they don't exist. |
| -m | Change only the modification time. |
| -d [String] | Parse string and use it instead of current time. |
Interview Questions
basic
- What happens if you use `touch` on a file that already exists and is full of text? Does it delete the text?
intermediate
- Why is it called 'touch' instead of 'create'?