LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

touch

Create files and update timestamps

TLDR

Create a new empty file
$ touch [file]
copy
Create multiple files
$ touch [file1] [file2] [file3]
copy
Update access and modification time to current time
$ touch [existing_file]
copy
Set specific modification time
$ touch -t [[CC]YY]MMDDhhmm[.ss] [file]
copy
Set time from another file
$ touch -r [reference_file] [file]
copy
Change only access time
$ touch -a [file]
copy
Change only modification time
$ touch -m [file]
copy
Do not create file if it doesn't exist
$ touch -c [file]
copy

SYNOPSIS

touch [options] file...

DESCRIPTION

touch updates file access and modification timestamps. If the file doesn't exist, touch creates an empty file (unless -c or -h is specified).Common uses include creating empty files, updating timestamps to trigger make rebuilds, and setting specific times for testing or archival purposes.Time can be specified in several formats: -t for precise timestamps, -d for human-readable strings ("yesterday", "2 hours ago"), or -r to copy times from another file.Without -a or -m, both access time (atime) and modification time (mtime) are updated. Change time (ctime) is always updated by the kernel when timestamps change.

PARAMETERS

-a

Change only access time
-m
Change only modification time
-c, --no-create
Do not create file if it doesn't exist
-d string, --date=string
Parse string and use instead of current time
-r file, --reference=file
Use times from reference file
-t stamp
Use timestamp [[CC]YY]MMDDhhmm[.ss] instead of current time
-h, --no-dereference
Affect symbolic link instead of referenced file
--time=WORD
Change the specified time: access, atime, use are equivalent to -a; modify, mtime are equivalent to -m
-f
Ignored; provided for compatibility with BSD versions of touch

DATE STRING EXAMPLES

$ touch -d "2024-01-15 10:30:00" file
copy
$ touch -d "yesterday" file
copy
$ touch -d "2 weeks ago" file
copy
$ touch -d "next monday" file
copy

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Creating files requires write permission in the directory. Updating timestamps requires write permission on the file or ownership.Some filesystems mount with noatime or relatime, which affects how access times are recorded. This doesn't affect touch but may affect programs relying on atime.Touch cannot change ctime (inode change time); it's always set to current time by the kernel when metadata changes.

SEE ALSO

stat(1), date(1), ls(1), mkdir(1), chmod(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid