How to Use the touch Command in Linux

How to Use the touch Command in Linux

After `touch report.txt`, `wc -c report.txt` can report zero even though the path now exists. I’m curious about the timestamps `touch` assigns as it creates that empty file.

A file’s size and its timestamps tell you different things about what happened to it. Let’s look at the timestamp fields `touch` changes.

What the touch command changes

GNU touch sets atime and mtime to the current time by default and creates a missing path as an empty file, as documented in the Linux touch manual and the POSIX specification.

These timestamp names describe different events, so pick the field that matches the task.

FieldWhat it recordsCan touch set it?
Access time (atime)A recorded file access, such as reading its contentsYes, with -a or the default action
Modification time (mtime)When file data was last modifiedYes, with -m or the default action
Status-change time (ctime)When file metadata changedNo, the system updates it when metadata changes
Birth timeWhen the filesystem recorded the file’s creationNo, touch does not set it

Create empty files without changing existing contents

Pass one or more paths to create empty files that do not exist. When a path already exists, touch changes its timestamps and leaves its contents in place.

touch file1.txt

The terminal image shows the new path after touch file1.txt. I ran touch against a file that already held text, and its contents stayed put.

Terminal output showing touch file1.txt followed by ls listing file1.txt
touch creates file1.txt, then ls confirms the path exists.

Separate filenames with spaces to create several empty files in one call. Their initial permissions follow the process’s umask.

touch first.txt second.txt

Creating a placeholder is optional when you plan to add text immediately, because an editor can create the path as it saves. Compare other ways to create files on Linux or see how to edit files in Linux.

To update existing paths without creating missing ones, add -c or –no-create.

touch -c file2.txt

The directory listing shows file1.txt after touch -c file2.txt. It does not list file2.txt.

Terminal output showing touch -c file2.txt leaves file2.txt absent
With -c, touch leaves the missing file2.txt uncreated.

GNU touch suppresses creation and gives no diagnostic for that missing path.

Choose which timestamp to update

Use -a for atime or -m for mtime. Combine both flags when the task needs both timestamps, as the default operation already does.

CommandAccess/modification fields selected
touch file1.txtatime and mtime
touch -a file1.txtatime only
touch -m file1.txtmtime only
touch -am file1.txtatime and mtime

These flags select atime and mtime values. Linux also updates ctime when touch sets timestamps, as the timestamp interface manual explains.

GNU ls -l shows mtime by default, and –time=atime requests the access time instead.

Plain touch also updates mtime on an existing file. The screenshot compares the long listing before and after the command.

Terminal output showing ls -l before and after touch file1.txt
Plain touch updates the displayed modification time of an existing file.

The file is still zero bytes in both listings, so the timestamp change came without a content write.

The mtime screenshot shows touch -m advancing the displayed mtime while the earlier atime stays put. A read through cat can update atime, though the Linux inode manual notes that mount settings can suppress those updates.

Terminal output showing touch -m file1.txt and a changed modification time
touch -m changes the displayed modification time while the recorded access time stays earlier.

The listing after -m shows the updated modification time. The next screenshot asks ls to display atime so the access field is visible.

Terminal output showing touch -a file1.txt and ls displaying atime
GNU ls can display atime with –time=atime after touch -a.

The -a screenshot displays atime after the command. Without –time=atime, GNU ls -l displays mtime.

Copy timestamps from another file

GNU touch uses the reference file’s atime and mtime, so it creates a missing target with those timestamp values.

touch -r file1.txt file2.txt

The screenshot shows matching timestamps for both paths, because -r copies time metadata but not file data. I compared atime and mtime after the command, and both values matched.

Terminal output showing file2.txt receives file1.txt timestamps with touch -r
touch -r copies the reference file’s access and modification timestamps.

The reference option copies timestamps without writing file content.

Set a specific timestamp

GNU -d parses a date string and assigns it to atime and mtime. The string includes UTC, so stat returns a time with its zone made explicit.

touch -d '2026-09-30 03:30:00 UTC' explicit.txt && stat -c '%y %n' explicit.txt

I set an explicit UTC timestamp, and stat returned 03:30 +0000. The Linux date command covers more GNU date inputs.

Terminal output for setting and reading an explicit touch timestamp
GNU touch sets the requested date, and stat displays the stored modification time.

POSIX also defines -d with a restricted date-time form. GNU touch accepts more date strings, and -t takes a fixed numeric form in local time.

OptionInputTime zone behavior
-dDate stringPOSIX date-time form, with broader strings accepted by GNU touch
-t[[CC]YY]MMDDhhmm[.ss]Interpreted in local time
touch -t 202609300330 numeric.txt

The -t value follows [[CC]YY]MMDDhhmm[.ss] and uses local time. Include a century and year when the value must be unambiguous, and check the POSIX time format before using it in a portable script.

Know what touch cannot change

touch can set mtime without changing file bytes, so a build or sync tool may see a timestamp that does not describe the data.

  • It does not write content. On an existing file, touch preserves the bytes and sets timestamps. To create a nonempty file, use an editor or a command that writes the content.
  • It does not set ctime or birth time. The system changes ctime when file metadata changes. Birth time is separate and may not be available from the filesystem.
  • Permissions still apply. Setting arbitrary times requires ownership or sufficient privilege, as explained in the Linux utimensat manual. A read-only filesystem or denied access also prevents the update.
  • Symbolic links have their own boundary. The default follows a symbolic link to its target. GNU -h requests an update to the link itself where supported, as explained in the guide to symbolic links.
  • Stored precision varies. A filesystem can round timestamps to its supported resolution, so a displayed value may not preserve every fraction supplied.

The Linux inode manual defines ctime as the status-change timestamp and birth time as the file-creation timestamp. A separate operation such as changing file ownership can update ctime too.

A timestamp describes metadata, not file contents

GNU stat can print access time beside its modification time. Include the ctime format specifier when you need the status-change timestamp too.

stat -c '%n atime=%x mtime=%y ctime=%z' explicit.txt

A newer mtime records a later data-modification timestamp, regardless of what the bytes contain. Read the file to inspect its contents.

Questions about the touch command

What does the touch command do in Linux?

GNU touch updates a file’s access and modification timestamps. If the path does not exist, it creates an empty file unless you use -c.

Does touch change the contents of an existing file?

No. On an existing file, touch changes timestamps and leaves the file contents in place.

How do you create multiple empty files with touch?

Pass the filenames as separate arguments, such as touch first.txt second.txt.

What is the difference between touch -d and touch -t?

GNU -d parses a date string. -t accepts a structured numeric timestamp in local time, with the format [[CC]YY]MMDDhhmm[.ss].

Can touch change a file’s creation time?

No. Touch sets access and modification times. The status-change time updates when metadata changes, and birth time is separate where the filesystem exposes it.