ADVERTISEMENT

Linux Commands ❯ touch

touch

Update the access and modification times of each existing FILE to the current time or create new EMPTY files
syntax:

touch [OPTION]... FILE...
  • touch my_file1
    if my_file1 already exists, set its access, modification, and change times (atime, mtime, and ctime) to the current system time. If my_file1 does not exist, create an empty file with that name with current system time.
  • touch my_file1 my_file2
    if my_file1 and my_file2 already exists, set its access, modification, and change times (atime, mtime, and ctime) to the current system time. If my_file1 and my_file2 are not existing, create empty files with that names with current system time.
  • touch *
    set the access, modification, and change times (atime, mtime, and ctime) of all the files and directories in the current directory to the current system time.
  • touch */
    set the access, modification, and change times (atime, mtime, and ctime) of all the directories(NOT FILES) in the current directory to the current system time.
  • touch my_file{1..5}
    create 5 empty files as names my_file1, my_file2, my_file3, my_file4 and my_file5
  • touch -a my_file1
    set the access time(atime) and Change time(ctime) of existing my_file1 to the current system time. Modification time(mtime) will not be changed. my_file1 will be created if it does not exist.
  • touch -c my_file1
    if my_file1 exists, set its access, modification, and change times (atime, mtime, and ctime) to the current system time. If my_file1 does not exist, do nothing.
  • touch -d "jan 2" my_file1
    set the access time(atime) and Change time(ctime) of existing my_file1 to JAN 2nd current year. Modification time(mtime) will not be changed. my_file1 will be created if it does not exist
  • touch -d "jan 2 2000" my_file1
    set the access time(atime) and Change time(ctime) of existing my_file1 to JAN 2nd 2000. Modification time(mtime) will not be changed. my_file1 will be created if it does not exist
  • touch -h my_file1_link1
    update the times of symbolic link my_file1_link1, not the file which is pointing to.
  • touch -r my_file1 my_file2
    set the access time(atime) and Change time(ctime) of existing my_file2 to match/reference with the times of my_file1 . Modification time(mtime) will not be changed. my_file2 will be created if it does not exist.
  • touch -t 201712011430.30 my_file1
    set the access time(atime) and Change time(ctime) of existing my_file1 to 2017 Dec 1st 14:30:30. Modification time(mtime) will not be changed. my_file1 will be created if it does not exist