Using touch command

touch Creates a file without content

touch file_name

For multiple files

touch File_name1 File2_name2 File_name3

Running touch on an already existing file: the file’s access and modification timestamps are updated to the current time, the content is not modified

touch -a To modify the access time only

touch -a file_name

touch -am Change access and modification time together

touch -am file_name

touch -c To check if file is created or not

touch -c file_name

-d option Use string with date instead of current time
touch -c -d "2020-03-09 11:33:12.000000000 +0100" file_name
-t option Use timestamp instead of current time. Format [[CC]YY]MMDDhhmm[.ss] touch -c -t 202003091133 file_name

touch -m This is used to change the modification time only
touch -m file_name

touch -r This command is used to copy only the timestamp onto another file

touch -r reference_file_name target_file_name

touch -h For modifying a symbolic link, not the pointed to

touch -h symbolic_link_file

Create several files touch

# Create files with names A to Z
$ touch {A..Z}
# Create files with names 1 to 20
$ touch {1..20}
# Create files with extension
$ touch {1..1000}.txt
# Create 10K files
$ touch {1..10}{1..1000}

Using touch to restore timestamps in a directory tree

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r–r–):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

And to change file and directories timestamp

find . -exec touch {} \;

Only files

find . -type f -exec touch {} \;