• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

touch Command Examples in Linux

by admin

The touch command changes the time of access or modification time of a file to the current time, or to the time specified in an argument. It is also used to create an empty file with the specified file name, assuming the file does not exist. This is often useful in testing permissions or in simply creating files that will later be processed by some application.

The original purpose of the touch command is to update a file’s timestamp to the current date and time without modifying it. The touch command can also be used to create an empty file of size 0 bytes. We cannot enter any text in the file with the touch command, but we can create multiple new files with a single command.

Syntax

The syntax of the touch command is:

$ touch {file names}

touch Command Example

1. Create a new empty file(s) or change the times for existing file(s) to current time:

# touch path/to/file

2. Set the times on a file to a specific date and time:

# touch -t YYYYMMDDHHMM.SS path/to/file

3. Set the time on a file to one hour in the past:

# touch -d "-1 hour" path/to/file

4. Use the times from a file to set the times on a second file:

# touch -r path/to/file1 path/to/file2

5. Create multiple files:

# touch path/to/file{1,2,3}.txt

Conclusion

touch command updates the access time and modification time (and dates) to the current time and date for one or more files. touch is useful in forcing other commands to handle files a certain way; for example, the operation of make, and sometimes find, relies on a file’s access and modification time. If a file doesn’t exist, touch creates it with a file size of 0.

Filed Under: Linux

Some more articles you might also be interested in …

  1. dive: A tool for exploring a Docker image, layer contents, and discovering ways to shrink it
  2. “git ignore” Command Examples
  3. auditd Command Examples in Linux
  4. encfs: Mounts or creates encrypted virtual filesystems
  5. DHCP configuration file /etc/dhcp/dhcpd.conf explained
  6. rc-status: command not found
  7. bat: command not found
  8. How to uninstall rhythmbox-plugins from Ubuntu
  9. lorem Command Examples
  10. fprintd-enroll: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright