0
0
Linux CLIscripting~10 mins

touch (create empty files) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - touch (create empty files)
Start
Run touch command
Check if file exists
Update timestamp if file exists
Create empty file
End
The touch command checks if a file exists. If yes, it updates the timestamp. If no, it creates an empty file.
Execution Sample
Linux CLI
touch file1.txt
ls -l file1.txt
Creates an empty file named file1.txt if it doesn't exist, then lists its details.
Execution Table
StepCommandActionResultOutput
1touch file1.txtCheck if file1.txt existsNoNo output
2touch file1.txtCreate empty file file1.txtSuccessNo output
3ls -l file1.txtList file detailsSuccess-rw-r--r-- 1 user user 0 date time file1.txt
4touch file1.txtFile exists, update timestampSuccessNo output
5ls -l file1.txtList file details with updated timestampSuccess-rw-r--r-- 1 user user 0 date updated_time file1.txt
💡 Command ends after file creation or timestamp update with no errors.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 4Final
file1.txt existenceNoNoYes (empty file created)Yes (timestamp updated)Yes (timestamp updated)
Key Moments - 3 Insights
Why does touch not show any output when creating a file?
Because touch is designed to silently create or update files without printing messages, as seen in execution_table steps 1 and 2.
What happens if the file already exists when using touch?
Touch updates the file's timestamp without changing its content, shown in execution_table step 4.
Does touch add any content to the file when creating it?
No, touch creates an empty file with zero bytes, as shown by the file size 0 in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the file size of file1.txt after step 3?
AUnknown
B1 byte
C0 bytes
DFile does not exist
💡 Hint
Check the output column in step 3 showing file details including size.
At which step does touch update the timestamp of an existing file?
AStep 4
BStep 2
CStep 1
DStep 3
💡 Hint
Look for the action describing timestamp update in the execution_table.
If file1.txt already exists, what will touch do according to the execution_table?
ACreate a new file with the same name
BUpdate the file's timestamp
CDelete the file
DPrint an error message
💡 Hint
Refer to step 4 in the execution_table where the file exists.
Concept Snapshot
touch filename

- Creates an empty file if it does not exist.
- If file exists, updates its last modified timestamp.
- No output is shown on success.
- Useful for creating or refreshing files quickly.
Full Transcript
The touch command in Linux is used to create an empty file or update the timestamp of an existing file. When you run 'touch file1.txt', the system checks if the file exists. If it does not, touch creates an empty file with zero bytes. If the file exists, touch updates its last modified timestamp without changing the content. The command runs silently without output. You can verify the file creation or timestamp update by listing the file details with 'ls -l file1.txt'. This command is simple and useful for quickly creating or refreshing files.