MTI TEK
  • Home
  • About
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All Resources
Linux-Ubuntu | rm -- remove files/directories
  1. Notes
  2. Examples
  3. Command Help (man rm)

  1. Notes
    rm source_file ...
    
    The rm command is not reversible. The shell doesn't provide a Trash from where the deleted files and directories can be restored.
    The option -i can be used to request confirmation before deleting a file or a directory.
  2. Examples
    • Remove a file (see below the option -i to request confirmation before deleting the file):
      $ rm file1
      
    • Remove all files (excluding subdirectories and files starting with a period (.)) in the folder:
      $ rm folder1/*
      
      It may complain that there are subdirectories in folder1: "rm: folder1/folder11: is a directory".

    • Remove all files starting with a period (.) in a folder (excluding sub-directories).
      $ rm folder1/.*
      
      It may show this warning: "rm: "." and ".." may not be removed".

    • Remove the directory and all its contents:
      $ rm -r folder1
      
  3. Command Help (man rm)
    The following options can be used:
    -r, -R, --recursive
        Remove directories and their contents recursively.
    
    -f, --force
        Ignore nonexistent files and arguments, never prompt.
    
    -i
        Prompt before every removal.
    
    -I
        Prompt once before removing more than three files, or when removing recursively.
    
    -v, --verbose
        Explain what is being done.
    
    --preserve-root
        Do not remove '/' (default).
    
    --no-preserve-root
        Do not treat '/' specially.
    
    -d, --dir
        Remove empty directories.
    
© 2025 mtitek