Skip to main content

touch

Explanation

The touch command is primarily used to update the access and modification times of a file to the current time. If the file does not exist, touch creates an empty file, which is its most common use case for beginners.

Basic Syntax

touch [OPTION]... FILE...

Common Flags and Options

FlagDescription
-aChange only the access time.
-mChange only the modification time.
-c, --no-createDo not create any files if they don't exist.
-d, --date=STRINGParse string and use it instead of current time.
-r, --reference=FILEUse this file's times instead of current time.

Real-world Examples

  1. Create an empty file:

    touch newfile.txt
  2. Create multiple empty files:

    touch file1.txt file2.txt file3.txt
  3. Update timestamps of an existing file:

    touch existingfile.txt