←Command Line/Guided Lab Create Files and Set Times with touch60:00
Click the virtual machine below to start practicing
>_ Tekhnikum | Lab
Setting up virtual machine…
Preparing lab files…
Starting terminal services…
This lab machine has stopped
Your progress through the guide is saved. Start a fresh machine to keep practicing.
Introduction
touch does two jobs: it creates empty files, and it updates the timestamps of files that already exist. ~/project contains notes.txt, last modified back in 2020.
This lab is the hands-on companion to the touch lesson from Linux Journey (CC BY-SA 4.0).
Create Empty Files
Name as many files as you like:
touch file1.txt file2.txt file3.log
ls -l
The new files have size 0.
Refresh a Timestamp
Look at the date on notes.txt, touch it, and look again:
ls -l notes.txt
touch notes.txt
ls -l notes.txt
The contents are untouched; only the modification time moves to now.
Set an Exact Time
-d sets a specific date and time instead of now:
touch -d "2026-06-23 12:30" file1.txt
ls -l file1.txt
-rw-r--r-- 1 learner learner 0 Jun 23 12:30 file1.txt
Don't Create by Accident
A typo in a filename makes a new empty file. -c (no-create) only touches files that already exist:
touch -c ghost.txt
ls ghost.txt
ls: cannot access 'ghost.txt': No such file or directory
Summary
touch name creates an empty file if it doesn't exist.
On an existing file it updates the modification time to now.