Exploring touch - Linux Commands

| 2 min read

What is a touch command?

In Linux, the touch command is used to create empty files and update the access and modification timestamps of existing files. It is a versatile command with several options, but its primary purpose is to update the timestamp of a file or create a new file if it doesn’t exist.

Here’s the basic syntax of the touch command:

touch [options] file1 file2 file3
  1. c or -no-create:

    • This is to check the specific file. If the file is present, it updates the access, modification, and change time, however, if the file doesn’t exist, it takes no action to create a new file.
    touch -c filename
  2. t or -time:

    • The t option allows you to specify a custom timestamp for the file’s access and modification times. This can be useful in certain scripting or automation scenarios.
    touch -t YYYYMMDDhhmm.ss filename
    
    # Example: Set the timestamp to January 31, 2023, 14:30:00
    # touch -t 202301311430.00 filename
  3. a or -time=access:

    • The a option is used to change only the access time of a file, leaving the modification time unchanged.
    touch -a filename
  4. m or -time=modify:

    • The m option is used to change only the modification time of a file, leaving the access time unchanged.
    touch -m filename

If you want to learn more about the touch command and its options directly in the terminal, you can use the man command for the manual.

man touch

Resources

Linux Command - touch

Thank you!

Thank you for your time and for reading this!