😎
CS1.dev
  • Welcome to Computer Science 1
  • Unit 2
    • Activity 2.1
    • Activity 2.2
    • Activity 2.3
    • Activity 2.4
    • Activity 2.5
    • Activity 2.6
    • Activity 2.7
    • Activity 2.9
    • Activity 2.10
    • Project 2
    • Activity 2.8
    • Activity 2.11
    • Activity 2.12
    • Activity 2.13
    • Activity 2.14
    • Activity 2.15
    • Activity 2.16
    • Activity 2.17
    • Activity 2.18
    • Activity 2.19
    • Project 3
    • Activity 2.20
    • Activity 2.21
    • Activity 2.22
    • Activity 2.23
    • Activity 2.24
    • Project 4
    • Activity 2.25
    • Activity 2.26
    • Activity 2.27
    • Activity 2.28
    • Project 5
    • Activity 2.29
    • Activity 2.30
    • Activity 2.31
    • Activity 2.32
    • Activity 2.33
    • Activity 2.34
    • Activity 2.35
    • Activity 2.36
  • Unit 3
    • Activity 3.1
    • Activity 3.2
    • Activity 3.3
    • Activity 3.4
    • Activity 3.5
    • Activity 3.6
    • Activity 3.7
    • Activity 3.8
    • Activity 3.9
    • Activity 3.10
    • Activity 3.11
    • Project 6
    • Activity 3.12
  • Activity 3.13
  • Activity 3.14
  • Activity 3.15
  • Activity 3.16
  • Project 7
  • Activity 3.17
  • Activity 3.18
  • Activity 3.19
  • Project 8
  • Linux
    • bash
    • cat
    • cd
    • chmod
    • df
    • echo
    • find
    • grep
    • less
    • ls
    • mkdir
    • more
    • pwd
    • tar
    • touch
    • unzip
    • zip
Powered by GitBook
On this page
  1. Linux

touch

The touch command in Linux is a versatile and commonly used utility for file handling. Its primary purpose is to create new, empty files and to update the access and modification timestamps of existing files. Here are some essential points about the touch command:

  1. Creating New Files: When you use touch followed by a filename, it creates a new file with that name if it doesn’t already exist. For example, touch newfile.txt will create an empty file named newfile.txt.

  2. Updating Timestamps: If the file specified with the touch command already exists, it updates the file’s access and modification timestamps to the current time. This is often used to quickly update these timestamps without modifying the file content.

  3. Multiple Files: You can create or update timestamps for multiple files at once by listing them with the command. For example, touch file1.txt file2.txt file3.txt will create or update all three files.

  4. Creating Files with Specific Timestamps: You can use touch with options -a, -m, and -t to set specific access and modification times. The -a option modifies only the access time, -m modifies only the modification time, and -t specifies a particular timestamp.

  5. No Content Change: Using touch on existing files does not alter their content. It is a safe way to change file timestamps without risking any data modification.

  6. Filesystem Checks: System administrators sometimes use touch to create marker files that can be used to check the status or existence of a particular process or operation at a specific time.

  7. Script Usage: In scripting, touch is often used to create a new file as a placeholder or a flag, indicating that a particular process or action has been completed.

  8. Error Handling: If touch tries to access a file that doesn't exist and it doesn't have permission to create a new file, or if it tries to modify a file without the proper permissions, it will return an error.

PrevioustarNextunzip

Last updated 1 year ago