Skip to content

Latest commit

 

History

History
116 lines (75 loc) · 2.21 KB

File metadata and controls

116 lines (75 loc) · 2.21 KB

rm

The rm (remove) command is used to delete files and directories in a Linux filesystem.

Basic Usage

  • Syntax:

    rm [options] [file...]
  • Examples:

    rm file.txt
    • Removes the file named file.txt.
    rm -r directory
    • Recursively removes the directory and its contents.
    rm -f file.txt
    • Forcibly removes file.txt without prompting, even if it's write-protected.
    rm -i file.txt
    • Prompts for confirmation before removing file.txt.
    rm -v file.txt
    • Verbosely shows what is being removed.

Common Options

  • -r or --recursive:

    • Removes directories and their contents recursively.
    rm -r folder
    • Removes the folder directory and everything inside it.
  • -f or --force:

    • Forces removal of files without prompting, even if the file is write-protected.
    rm -f important.txt
    • Removes important.txt without any confirmation.
  • -i or --interactive:

    • Prompts for confirmation before each file is removed.
    rm -i file.txt
    • Asks for confirmation before deleting file.txt.
  • -v or --verbose:

    • Shows what is being removed.
    rm -v file.txt
    • Outputs a message that file.txt is being deleted.
  • --help:

    • Displays help information about the rm command.
    rm --help
    • Shows usage information and options.

Quick Tips

  • Be Cautious:

    • The rm command permanently deletes files and directories. There is no undo, so use it carefully, especially with options like -r and -f.
  • Removing Multiple Files:

    • You can remove multiple files at once by listing them after rm.
    rm file1.txt file2.txt
  • Wildcard Usage:

    • Use wildcards to remove multiple files that match a pattern.
    rm *.txt
    • Removes all .txt files in the current directory.

Summary

The rm command is powerful for removing files and directories in Linux. Use it with options like -r, -f, and -i to control how files and directories are deleted. Always double-check what you're removing, especially when using recursive or forced deletion.