Cheatsheets
HomeWriteupsResourcesCheatsheets
Linux
Linux
  • Know Yourself and Your System
    • id
    • logname
    • uname
    • w
    • who
    • whoami
  • Surfing / Knowing Your File System
    • cd
    • df
    • du
    • ls
    • pwd
    • stat
    • tree
  • Knowing About Files / Commands
    • alias
    • file
    • info
    • whatis
    • apropos
    • man
    • help
    • history
    • script
  • Manipulating Files / Directories
    • touch
    • mkdir
    • rm
    • rmdir
    • cp
    • mv
    • ln
  • Interacting with Files
    • cat
    • head
    • less
    • middle
    • more
    • tail
  • STROPS / Text Manipulation
    • awk
    • cut
    • grep
    • jq
    • join
    • paste
    • sed
    • sort
    • tr
    • uniq
    • xargs
    • xclip
    • wc
    • tee
    • echo
    • comm
    • diff
    • patch
    • aspell
    • Combos
  • Formatting the Output
    • nl
    • fold
    • fmt
    • pr
    • printf
  • Searching / Finding
    • find
    • locate
    • which
    • whereis
    • type
  • Web Interaction
    • curl
    • wget
  • xxd
  • References
Powered by GitBook
On this page
  • Introduction
  • Syntax
  • Important Flags
  • Time Stamp Formats
  • Examples

Was this helpful?

  1. Manipulating Files / Directories

touch

touch linux command cheatsheet by Thamizhiniyan C S

Introduction

The primary function of the touch command is to modify a file's timestamp. While it is often used to create files, this is not its main purpose.


Syntax

touch [OPTION]... FILE...


Important Flags

Flag
Description

-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 time

-t STAMP

use [[CC]YY]MMDDhhmm[.ss] instead of current time

--time=WORD

change the specified time: WORD is access, atime, or use: equivalent to -a: WORD is modify or mtime: equivalent to -m

--help

display this help and exit

--version

output version information and exit


Time Stamp Formats

Syntax: [[CC]YY]MMDDhhmm[.ss]

Format
Description

CC

the first two digits for a year

YY

the last two digits for a year

MM

the month

DD

the day

hh

the hour

mm

the minutes

ss

the seconds


Examples

Command
Description

To create a emtpy file

To create multiple files at the same time. These files will be empty upon creation.

To create ten files with appended numbering

To create ten files with appended alphabets

To change a file's access time to the current timestamp.

To modify access time explicitly.

To change both modification and access times to the current timestamp.

Checks if a file is created; if not, it doesn’t create it.

Updates both access and modification times.

To change a file's modification time to the current timestamp.

To set modification time explicitly.

Changes the modification date only.

To set a file's timestamp based on another file's timestamp.

Uses the timestamp of another file.

Creates a file with a specified time.

To set a specific timestamp for an existing file.

To modify the timestamp of a symbolic link without affecting the referenced file.

PreviousscriptNextmkdir

Last updated 11 months ago

Was this helpful?

touch filename
touch File1_name File2_name File3_name
touch test{1..10}
touch test_{a..j}
touch -a [filename]
touch -at [timestamp] [filename]
touch -am [filename]
touch -c fileName
touch -c -d fileName
touch -m [filename]
touch -mt [timestamp] [filename]
touch -d "17 Mar 2023" fileName
touch -r [reference file] [file]
touch -r second_file_name first_file_name
touch -t YYMMDDHHMM fileName
touch -t [timestamp] [existing_filename]
touch -h [filename]