Linux Terminal Command: touch
The touch command is an essential tool in Foundations & Navigation. In this tutorial, we will explore what touch does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The touch command updates the access and modification times of files. If a file does not exist, touch creates a new empty file.
Common Options & Syntax
touch [options] [arguments]
Here are the most common flags used with touch:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
touch document.md
What it does: Creates an empty file named ‘document.md’ if it does not exist, or updates its modification time to the current system time.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
touch -t 202607021200.00 old_file.log
What it does: Sets the access and modification times of ‘old_file.log’ to exactly July 2, 2026, at 12:00:00 PM.
⚙️ Warning & Common Pitfalls
[!WARNING] Do not use
touchto check if a file exists inside scripts, as it will overwrite its timestamps. Use shell conditionals ([ -f file ]) instead.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: