Skip to main content
Engineering LibreTexts

05-C.6.4: Working with Files and Directories - rm/touch Command

  • Page ID
    32192
  • The rm Command

    rm stands for remove, and it is used to remove files, directories, and links. By default, it does not remove directories.

    This command normally works silently and it should be used carefully, because once you delete a file in Linux the content cannot be recovered.

    Syntax:

    rm [OPTION]... FILE...
    

    There are a couple of common options, which you might notice are similar to the options for both cp and mv.

    Options Meaning
    -i Prompt before every removal.
    -r, -R, --recursive Remove directories and their contents recursively.

    The unlink command is very similar to the rm command, but only removes a single file at a time, and does not remove directories.

    The touch Command

    The touch command updates the access and modification times of each file to the current time. The touch command is a standard command in Linux used to create, change, and modify the timestamp of a file. If the file specified does not exist touch will create the file, but the file does not have any content.

    Syntax:

    touch file_name
    

    Command Options:

    Options Option Meaning
    -a Change only the access time.
    -c, --no-create Do not create any files.
    -d, --date=STRING Parse STRING and use it instead of current time.
    -h, --no-dereference Affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink).
    -m Change only the modification time.
    -r, --reference=FILE Use this file's times instead of current time.
    -t STAMP Use [[CC]YY]MMDDhhmm[.ss] instead of current time.
    --time=WORD Change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime.

    Adapted from:
    "rm command in Linux with examples" by AKASH GUPTA 6, Geeks for Geeks is licensed under CC BY-SA 4.0
    "touch command in Linux with Examples" by Bhumika_Rani, Geeks for Geeks is licensed under CC BY-SA 4.0