Copied to clipboard

touch

The touch command is a command-line tool for creating new empty files or updating the timestamp of existing files
e.g. 202201011200

Example

  1. Create a new file:

    touch new_file.txt
    

    This will create an empty file named new_file.txt in the current directory.

  2. Update the time stamp of an existing file:

    touch existing_file.txt
    

    This will update the access and modification time stamps of the file named existing_file.txt to the current time.

  3. Update the time stamp of a file with a specified time stamp:

    touch -t 202201011200 existing_file.txt
    

    This will update the access and modification time stamps of the file named existing_file.txt with the specified time stamp 202201011200.

  4. Update the time stamp of a file with the time stamp of another file:

    touch -r reference_file.txt existing_file.txt
    

    This will update the access and modification time stamps of the file named existing_file.txt with the time stamp of the file named reference_file.txt.

  5. Modify the modification time of a file:

    touch -m existing_file.txt
    

    This will only update the modification time stamp of the file named existing_file.txt to the current time, without updating the access time stamp.