touch Command in Linux: Create Files and Update Timestamps

By 

•

Updated on

•

8 min read

Using the Linux touch command to create files and update timestamps

The touch command allows you to update the timestamps on existing files and directories as well as create new, empty files.

This guide explains how to use the touch command through practical examples and detailed explanations of the most common command options.

touch Command Syntax

The general syntax for the touch command is:

txt
touch [OPTIONS] FILE...

Linux File Timestamps

Before going into how to use the touch command, let us start by reviewing the file timestamps in Linux.

A file in Linux has three standard timestamps:

  • atime (access time): The last time the file was accessed or opened by a command or application such as cat , vim, or grep .
  • mtime (modify time): The last time the file’s content was modified.
  • ctime (change time): The last time the file’s attributes or content changed. Attributes include file permissions, ownership, or location.

Most modern filesystems, such as ext4, XFS, and Btrfs, also record a birth (creation) time, but the touch command cannot change it.

To display the file status including all timestamps, use the stat command:

Terminal
stat file_name

Creating a new file requires write permissions on the parent directory. Otherwise, you will receive a permission denied error.

How to Use the touch Command

In its simplest form, when used without any options, if the file specified as an argument does not exist, touch will create a new empty file.

If the file already exists, touch will change the file’s last access and modification times to the current time.

For example, if file1 does not exist, the following command will create it; otherwise, it will update its timestamps:

Terminal
touch file1

To create or update multiple files at once, specify the file names as arguments:

Terminal
touch file1 file2 file3

To create a numbered set of files, use Bash brace expansion:

Terminal
touch file{1..5}.txt

The shell expands file{1..5}.txt to file1.txt file2.txt file3.txt file4.txt file5.txt and passes all five names to touch.

If you do not want the touch command to create new files, use the -c (--no-create) option.

For example, if file1 exists, the following command will update its timestamps; otherwise, it will do nothing:

Terminal
touch -c file1

Changing Only the Access or Modification Time

By default, if no option is used, touch will update both the access and modification times to the current time. Using the -a and -m options, you can change only one of these timestamps.

Change Only the Access Time

Use the -a option to change only the file’s access time:

Terminal
touch -a file1

Change Only the Modification Time

Use the -m option to change only the file’s modification time:

Terminal
touch -m file1

Whichever timestamp you change, the change time (ctime) is also updated to the current time. If you also need to manage permissions while updating timestamps, see the chmod command guide .

Setting Specific Timestamps

The touch command also allows you to update or create a file with a specific time other than the current time.

Use the -d (--date=) option to specify a date string:

Terminal
touch -d '1 June 2026 11:02' file1

The date string must be enclosed in single or double quotes.

To verify the new timestamps, run stat on the file:

Terminal
stat file1
output
  File: file1
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 253,1	Inode: 262163      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/linuxize)   Gid: ( 1000/linuxize)
Access: 2026-06-01 11:02:00.000000000 +0000
Modify: 2026-06-01 11:02:00.000000000 +0000
Change: 2026-10-14 20:43:43.598013715 +0000
 Birth: 2026-10-14 20:43:43.597007826 +0000

The Access and Modify lines show the date we passed to -d. The Change line shows the current time. The kernel updates ctime every time touch changes the other timestamps. Birth is the time the file was created.

You can also provide a partial date-time string. Providing only the date uses midnight as the time:

Terminal
touch -d '12 June' file1

The -d option accepts the same free-form date strings as the date command . This includes relative values such as yesterday or 2 days ago:

Terminal
touch -d '2 days ago' file1

Use the -t option to specify a timestamp in the following format:

txt
[[CC]YY]MMDDhhmm[.ss]

Each field is a two-digit number:

  • CC - The first two digits of the year
  • YY - The last two digits of the year
  • MM - The month (01-12)
  • DD - The day of the month (01-31)
  • hh - The hour (00-23)
  • mm - The minutes (00-59)
  • ss - The seconds (00-59)

The fields in square brackets are optional. If you leave out the year, touch uses the current year, and without .ss, the seconds are set to zero.

For example, the following command sets the access and modification times of file1 to June 1st, 11:02, of the current year:

Terminal
touch -t 06011102 file1

To set the year and seconds as well, use the full form. The following command sets the timestamps to June 1st, 2026, 11:02:30:

Terminal
touch -t 202606011102.30 file1

Using the Timestamp of Another File

The -r (--reference=) option allows you to specify a reference file and use its timestamps instead of the current time.

For example, the following command sets the timestamps of file2 to match those of file1:

Terminal
touch -r file1 file2

You can combine -r with a relative -d value to shift the time. The following command sets the timestamps of file2 to one hour earlier than those of file1:

Terminal
touch -d '-1 hour' -r file1 file2

By default, using touch on a symbolic link changes the timestamps of the file it points to, not the symlink itself.

Use the -h (--no-dereference) option to modify the timestamp of the symlink:

Terminal
touch -h symlink1

Quick Reference

CommandDescription
touch fileCreate empty file or update timestamps
touch file1 file2Create or update multiple files
touch -c fileUpdate timestamps only, do not create
touch -a fileUpdate access time only
touch -m fileUpdate modification time only
touch -d 'DATE' fileSet specific date and time
touch -d '2 days ago' fileSet a relative date
touch -t MMDDhhmm fileSet timestamp in numeric format
touch -r ref fileCopy timestamps from a reference file
touch -d '-1 hour' -r ref fileShift timestamps relative to a reference file
touch -h symlinkUpdate symlink timestamp, not target

Troubleshooting

“Permission denied” when creating a file
You need write permission on the directory where you are creating the file. Check permissions with ls -ld /path/to/directory and use sudo if necessary.

“No such file or directory” when creating a file
The touch command does not create parent directories. If newdir does not exist, touch newdir/file1 fails with cannot touch 'newdir/file1': No such file or directory. Create the directory first with mkdir -p , then run touch again.

“Operation not permitted” when setting a specific time
Write permission on a file is enough to update both its access and modification times to the current time. Changing only one timestamp with -a or -m, or setting a specific time with -d, -t, or -r, requires you to own the file or have appropriate privileges. Run the command as the file owner or with sudo. Ubuntu 25.10 and later ship the Rust rewrite of coreutils, and its touch reports the same error as Permission denied.

Access time does not change when reading a file
Most Linux distributions mount filesystems with the relatime option. With relatime, reading a file updates atime only if the previous atime is older than or equal to mtime or ctime, or more than 24 hours old. With noatime, reading a file never updates it. Neither option affects touch, and touch -a always sets the access time. Check the mount options with findmnt.

Cannot set ctime directly
The ctime (change time) cannot be set manually. The kernel updates it whenever file metadata or content changes. Only atime and mtime can be set with touch.

FAQ

What is the difference between atime, mtime, and ctime?
atime is updated when the file is read, mtime is updated when the file content changes, and ctime is updated when any metadata (permissions, ownership) or content changes. Only atime and mtime can be set directly with touch.

Does touch update ctime?
Yes, indirectly. Any time touch updates atime or mtime, the kernel also updates ctime because the file metadata has changed. You cannot set ctime to a custom value.

Can I use touch to create a file with content?
No, touch only creates empty files or updates timestamps. To create a file with content, use redirection or a text editor .

How do I check a file’s timestamps after using touch?
Use the stat command: stat filename. It shows the full access, modify, and change timestamps.

Does touch work on directories?
Yes. Running touch dirname updates the access and modification times of the directory itself, the same way it does for files.

Conclusion

The touch command is a simple but versatile utility for creating empty files and managing file timestamps in Linux. For other ways to create files, including files with content, see our guide on how to create a file in Linux .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page