The touch command in Linux is a versatile utility used primarily to create empty files or update file timestamps (access time and modification time). If the specified file does not exist, touch creates it as an empty file with default permissions based on the user's umask. If the file already exists, touch updates its access and modification times to the current system time.

Key Functions:

  • Create an empty file:
    touch filename creates a new empty file named filename.

  • Update timestamps:
    If the file exists, touch updates both access time (atime) and modification time (mtime) to the current time.

  • Update only access time:
    Use touch -a filename to update only the access time.

  • Update only modification time:
    Use touch -m filename to update only the modification time.

  • Set custom timestamps:
    Use touch -d 'DATE' filename to set a specific date and time (e.g., touch -d '2025-12-25 14:30' file.txt).

  • Use reference file timestamps:
    Use touch -r ref_file.txt target_file.txt to copy timestamps from ref_file.txt to target_file.txt.

  • Prevent file creation:
    Use touch -c filename to update timestamps only if the file exists — otherwise, do nothing.

  • Modify symbolic link timestamps:
    Use touch -h symlink to update the symlink’s timestamp instead of the target file.

Note: The ctime (change time) is automatically updated by the kernel whenever file metadata or content changes, including when touch modifies atime or mtime. It cannot be set directly with touch.

Example Usage:

touch newfile.txt           # Creates empty file
touch -a log.txt            # Updates only access time
touch -m -d "2026-03-03" data.txt  # Sets mtime to March 3, 2026
touch -r template.txt config.txt  # Copies timestamps from template to config

Use stat filename to verify timestamp changes after running touch.

What is the reason people 'touch' a file before writing it? They mostly don't. But many examples show use of touch(1) to create a file. Even if one wants to first create file, touch generally isn't the easiest nor most efficient way ... however it's relatively universal. E.g. even if one is using C-shell, and *nix all the way back to 1979 or earlier, issuing command touch file will generally create file (presuming sufficient permissions and such). But for Bourne and compatible shells (POSIX, Bash, etc.), much more efficient and less typing to do: >file to create file ... however that will truncate it if it already exists, whereas touch won't. >>file can be used to create it if it doesn't exist, and not truncate it even if it already exists. And, sometimes folks will want to create file with certain permissions or the like, before otherwise using it. E.g.: (umask 077 && >file) or: (umask 022 && >file) One can also create the file, then change permissions with chmod, but that's then an external command, as opposed to built-in to the shell, also, in the case of making permissions more secure, it's more secure to create the file with the more secure permissions to begin with ... notably because *nix checks permissions at (attempt) to open file, and generally not thereafter - so if someone/something opened it when it had weaker permissions, and still has it open, they continue to have the access they had when they opened the file, generally regardless of subsequent permission changes. used to give you error if you tried to write to a file that does not exist Not a thing, never was. Answer from michaelpaoli on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › touch-command-in-linux-with-examples
Creating an Empty File in Linux | Touch Command - GeeksforGeeks
The touch command in Linux is used to create an empty file or update the access and modification timestamps of existing files.
Published   December 8, 2025
🌐
Reddit
reddit.com › r/linuxquestions › what is the reason people 'touch' a file before writing it?
r/linuxquestions on Reddit: What is the reason people 'touch' a file before writing it?
December 9, 2023 -

People always seem to touch a new file before writing to it. But why? Considering that file gets created automatically when you try to write to it. For instance, I see people doing

touch myfile.txt
nano myfile.txt

When just doing nano myfile.txt would have already worked. Also,

touch log
echo ERROR > log

Could just very well be echo ERROR > log

Why?

Actually, I learned that very ancient distros of linux, linux 2.xish used to give you error if you tried to write to a file that does not exist. But we are not in the 1990s any more

Discussions

How to use the touch command in Linux?
I’m new to Linux and tried using the ‘touch’ command to create a file, but it’s not working as expected. Can someone explain how to properly use the ‘touch’ command, and what might be going wrong? More on mepis.org
🌐 mepis.org
0
September 7, 2024
How do I use the touch command in Linux?
I’ve been trying to create new empty files using the ‘touch’ command on my Linux system, but I’m not sure if I’m doing it right. Can someone explain how to properly use ‘touch’ and maybe point out common mistakes or pitfalls? I need to understand this to maintain my project files ... More on mepis.org
🌐 mepis.org
0
September 10, 2024
How to use touch command in linux bash script

Try redirecting a blank echo to create the file.

echo -n > myemptyfile.conf

Additionally, ensure the user and/or script has permission to write to the output directory. Also confirm that the file isn't already being created, but going somewhere you didn't realize (such as the current working directory if you're not providing an explicit path for the output).

More on reddit.com
🌐 r/linuxadmin
17
5
January 26, 2015
9 Useful Examples of Touch Command in Linux

What is the practical use of assessing or updating when you last opened a file?

More on reddit.com
🌐 r/linux4noobs
7
80
October 18, 2014
🌐
IBM
ibm.com › docs › ssw_aix_72 › t_commands › touch.html
touch Command
We cannot provide a description for this page right now
🌐
Server Academy
serveracademy.com › blog › how-to-use-the-touch-command-in-linux
How to Use the Touch Command in Linux - Server Academy
Introduction to the Touch Command The `touch` command in Linux is a fundamental tool used primarily for creating empty files and updating the timestamps of existing files. It is essential for system administrators and developers who need to ...
🌐
IONOS
ionos.com › digital guide › server › configuration › linux touch command
How to use the Linux touch command - IONOS
December 6, 2023 - By using the options, you can choose whether the system time is used or if another timestamp is to be used. The touch command is used in Linux to change timestamps and access stamps in individual files or directories.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to use touch command in linux
How to Use touch Command in Linux (12 Examples)
December 19, 2025 - A system running Linux. Access to the command line/terminal. Basic terminal commands, such as ls. ... The touch utility works without any options or with multiple options for advanced queries. Some options have a long and short format. If an option requires additional information, then the data is mandatory for both long and short forms.
Find elsewhere
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › touch.1.html
touch(1) - Linux manual page
A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output. Mandatory arguments to long options are mandatory for short options too. -a change only the access time -c, --no-create do not create any files -d, --date=STRING parse STRING and use it instead of current time -f (ignored) -h, --no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink) -m change only the modification time -r, --reference=FILE use this file's times instead of current
🌐
Mepis
mepis.org › linux
How to use the touch command in Linux? - Linux - Mepis Forum
September 7, 2024 - I’m new to Linux and tried using the ‘touch’ command to create a file, but it’s not working as expected. Can someone explain how to properly use the ‘touch’ command, and what might be going wrong?
🌐
Hostinger
hostinger.com › home › tutorials › linux touch command: what it is + examples of how to use it to modify timestamps
What Is Linux Touch Command + Practical Usage Examples
August 21, 2025 - The Linux touch command is a standard command used to modify the timestamps of a file. Learn how to use the touch command in this article.
🌐
iO Flood
ioflood.com › blog › touch-linux-command
Using the Touch Command in Linux | Reference Guide
December 19, 2023 - Many users find themselves puzzled when it comes to handling file creation or modification in Linux, but we’re here to help. Think of the ‘touch’ command in Linux as a skilled craftsman – allowing us to create, change, and modify timestamps of files with ease.
🌐
Baeldung
baeldung.com › home › files › guide to the linux touch command
Guide to the Linux touch Command | Baeldung on Linux
March 18, 2024 - In this tutorial, we’ll learn about the touch command. One application of this command is to update the last modified time and last accessed time of a file or directory.
🌐
Rackspace
docs.rackspace.com › docs › create-files-in-linux
Create files by using the command line in Linux
Type $ touch followed by the name of the file you want to create. ... To verify that you created the file successfully, type $ ls <name of your file>. ... You should see the new file in the list of files in the directory.
🌐
Mepis
mepis.org › linux
How do I use the touch command in Linux? - Linux - Mepis Forum
September 10, 2024 - I’ve been trying to create new empty files using the ‘touch’ command on my Linux system, but I’m not sure if I’m doing it right. Can someone explain how to properly use ‘touch’ and maybe point out common mistakes or pitf…
🌐
DigitalOcean
digitalocean.com › community › tutorials › linux-commands
50+ Essential Linux Commands: A Comprehensive Guide | DigitalOcean
April 8, 2025 - The touch command in Linux creates an empty file or updates the timestamp of an existing file.
🌐
LinuxTechi
linuxtechi.com › home › commands › 9 useful touch command examples in linux
9 Useful Touch Command Examples in Linux
April 14, 2024 - Let’s assume we have a ‘nfsshare’ folder under /mnt, Let’s change the access time of this folder using the below command, [root@linuxtechi ~]# touch -a /mnt/nfsshare/ [root@linuxtechi ~]# [root@linuxtechi ~]# stat /mnt/nfsshare/ File: ‘/mnt/nfsshare/’ Size: 6 Blocks: 0 IO Block: 4096 directory Device: fd00h/64768d Inode: 2258 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:mnt_t:s0 Access: 2018-03-29 23:34:38.095000000 -0400 Modify: 2018-03-03 10:42:45.194000000 -0500 Change: 2018-03-29 23:34:38.095000000 -0400 Birth: - [root@linuxtechi ~]#
🌐
Medium
medium.com › @yadavsunil9699 › linux-touch-command-d8b5a02037d6
Linux touch Command. In the world of Linux, the touch… | by Yadavsunil | Medium
January 4, 2024 - The touch command in Linux is a handy tool for managing file timestamps and creating new files. Its simple yet effective functionality makes it a fundamental part of any Linux user's toolkit.
🌐
Linuxize
linuxize.com › home › linux commands › touch command in linux: create files and update timestamps
touch Command in Linux: Create Files and Update Timestamps | Linuxize
5 days ago - The touch command creates empty files and updates file timestamps in Linux. This guide covers access time, modification time, custom timestamps, and reference file usage.