firoz@rhel:~$
all notes
Linux BasicsCompletedJune 2026

Linux Command: touch

A quick teaching note on using touch to create empty files and update file timestamps from the Linux shell.

linuxshellfilestimestamps

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
VM screenshot
Linux terminal showing touch notes.txt and ls -l notes.txt output

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
Terminal output
$ 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
Terminal output
$ touch file_{1..9}.txt
$ ls file_*.txt
file_1.txt file_2.txt file_3.txt file_4.txt file_5.txt
file_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
Terminal output
$ 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
Terminal output
$ 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
Terminal output
$ 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
Terminal output
$ touch existing-file.txt
$ touch -c existing-file.txt
$ touch -c missing-file.txt
$ ls -l existing-file.txt missing-file.txt
ls: 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
Terminal output
$ touch -t 202606220900 original.txt
$ touch copied-time.txt
$ touch -r original.txt copied-time.txt
$ stat original.txt copied-time.txt
File: original.txt
Access: 2026-06-22 09:00:00.000000000 +0300
Modify: 2026-06-22 09:00:00.000000000 +0300
File: copied-time.txt
Access: 2026-06-22 09:00:00.000000000 +0300
Modify: 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
Terminal output
$ touch notes.txt
$ stat notes.txt
File: notes.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Access: 2026-06-18 10:32:14.000000000 +0300
Modify: 2026-06-18 10:32:14.000000000 +0300
Change: 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
Terminal output
$ touch -t 202606181030 notes.txt
$ stat notes.txt
File: notes.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Access: 2026-06-18 10:30:00.000000000 +0300
Modify: 2026-06-18 10:30:00.000000000 +0300
Change: 2026-06-18 10:33:02.000000000 +0300