Skip to main content
Engineering LibreTexts

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

  • Page ID
    32192
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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 Option 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


    05-C.6.4: Working with Files and Directories - rm/touch Command is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by LibreTexts.