Linux Command: touch
A quick teaching note on using touch to create empty files and update file timestamps from the Linux shell.
Purpose
Use touch when you need a new empty file for practice, scripts, configuration placeholders, or when you need to refresh a file's access and modification time.
Key points
- ›touch creates a file if it does not already exist.
- ›If the file already exists, touch updates its access and modification timestamps.
- ›Multiple files can be created or updated with one command.
- ›The -t option lets you set a specific timestamp in [[CC]YY]MMDDhhmm[.ss] format.
Notes
Note 1
Create one empty file
This is the most common beginner use: create a blank file in the current directory.
$ touch notes.txt$ ls -l notes.txt

Note 2
Create multiple files
Pass more than one filename to create or update several files in a single command.
$ touch lesson1.txt lesson2.txt lesson3.txt$ ls -l lesson*.txt
$ touch lesson1.txt lesson2.txt lesson3.txt$ ls -l lesson*.txt-rw-r--r-- 1 firoz firoz 0 Jun 18 10:31 lesson1.txt-rw-r--r-- 1 firoz firoz 0 Jun 18 10:31 lesson2.txt-rw-r--r-- 1 firoz firoz 0 Jun 18 10:31 lesson3.txt
Note 3
Create numbered files with brace expansion
Brace expansion lets the shell generate a sequence of filenames before touch runs. This command creates nine empty files named file_1.txt through file_9.txt.
$ touch file_{1..9}.txt$ ls file_*.txt
$ touch file_{1..9}.txt$ ls file_*.txtfile_1.txt file_2.txt file_3.txt file_4.txt file_5.txtfile_6.txt file_7.txt file_8.txt file_9.txt
Note 4
Create a file inside a directory
touch can create a file inside an existing directory, but it will not create the directory for you. Create the directory first if it does not exist.
$ mkdir -p logs$ touch logs/app.log$ ls -l logs/app.log
$ mkdir -p logs$ touch logs/app.log$ ls -l logs/app.log-rw-r--r-- 1 firoz firoz 0 Jun 22 10:15 logs/app.log
Note 5
Create a hidden file
In Linux, filenames that start with a dot are hidden by default. touch is often used to create hidden config files.
$ touch .env$ ls -la .env
$ touch .env$ ls -la .env-rw-r--r-- 1 firoz firoz 0 Jun 22 10:16 .env
Note 6
Create files with different extensions
You can create multiple files with different names and extensions in one command.
$ touch index.html styles.css app.js$ ls -l index.html styles.css app.js
$ touch index.html styles.css app.js$ ls -l index.html styles.css app.js-rw-r--r-- 1 firoz firoz 0 Jun 22 10:17 app.js-rw-r--r-- 1 firoz firoz 0 Jun 22 10:17 index.html-rw-r--r-- 1 firoz firoz 0 Jun 22 10:17 styles.css
Note 7
Update timestamp only if the file exists
Use -c when you only want to update the timestamp of an existing file. If the file does not exist, touch will not create it.
$ touch existing-file.txt$ touch -c existing-file.txt$ touch -c missing-file.txt$ ls -l existing-file.txt missing-file.txt
$ touch existing-file.txt$ touch -c existing-file.txt$ touch -c missing-file.txt$ ls -l existing-file.txt missing-file.txtls: cannot access 'missing-file.txt': No such file or directory-rw-r--r-- 1 firoz firoz 0 Jun 22 10:19 existing-file.txt
Note 8
Copy timestamp from another file
Use -r to make one file use the same timestamp as another file.
$ touch -t 202606220900 original.txt$ touch copied-time.txt$ touch -r original.txt copied-time.txt$ stat original.txt copied-time.txt
$ touch -t 202606220900 original.txt$ touch copied-time.txt$ touch -r original.txt copied-time.txt$ stat original.txt copied-time.txtFile: original.txtAccess: 2026-06-22 09:00:00.000000000 +0300Modify: 2026-06-22 09:00:00.000000000 +0300File: copied-time.txtAccess: 2026-06-22 09:00:00.000000000 +0300Modify: 2026-06-22 09:00:00.000000000 +0300
Note 9
Update an existing file timestamp
When the file already exists, touch leaves the content unchanged and refreshes the timestamp.
$ touch notes.txt$ stat notes.txt
$ touch notes.txt$ stat notes.txtFile: notes.txtSize: 0 Blocks: 0 IO Block: 4096 regular empty fileAccess: 2026-06-18 10:32:14.000000000 +0300Modify: 2026-06-18 10:32:14.000000000 +0300Change: 2026-06-18 10:32:14.000000000 +0300
Note 10
Set a custom timestamp
Use -t when you need a predictable timestamp for testing, sorting, or demonstrations.
$ touch -t 202606181030 notes.txt$ stat notes.txt
$ touch -t 202606181030 notes.txt$ stat notes.txtFile: notes.txtSize: 0 Blocks: 0 IO Block: 4096 regular empty fileAccess: 2026-06-18 10:30:00.000000000 +0300Modify: 2026-06-18 10:30:00.000000000 +0300Change: 2026-06-18 10:33:02.000000000 +0300