The primarily use of the Linux touch command is to update or modify the timestamp of files or directories.if the file does not exist the touch command will create it as an empty file.Touch is commonly used for file creation while it's not its original goal.
touch file1 file2 file3
gives :
ls -l
total 0
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file1
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file2
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file3
touch file 1
access and modification time are updated :
ls -l
total 0
-rw-rw-r-- 1 sc sc 0 juil. 20 14:41 file1
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file2
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file3
Using -a or -m options let us change access only or modification time only.
touch -a file1
changes only access time :
ls -lu
total 0
-rw-rw-r-- 1 sc sc 0 juil. 20 14:44 file1
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file2
-rw-rw-r-- 1 sc sc 0 juil. 20 14:28 file3
whereas -m updates modification time only
touch -m file1
stat file1
File: file1
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 259,4 Inode: 2910077 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ sc) Gid: ( 1000/ sc)
Access: 2025-07-20 14:49:26.160088175 +0100
Modify: 2025-07-20 14:49:25.422095884 +0100
Change: 2025-07-20 14:49:25.422095884 +0100
Birth: 2025-07-20 14:28:08.811618076 +0100
touch *.txt
will update the timestamps of all text files in the directory.
file1 is used as reference file
touch -r file1 file2
touch -t [[CC]YY]MMDDhhmm[.ss] <filename>
The digits in the square brackets are optional. When using the two-digit year format, setting YY to any number between 0-68 automatically assumes CC is 20, whereas 69-99 assumes CC is 19. Example :
touch -t 202507200915.30 file4
The -d option allows to use many human-readable forms :
touch -d yesterday file1
sources : man page phoenixNap vitux