• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All
  • About
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 bellow 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
      $ rm -R folder1
  3. Command Help (man rm)
    The following options can be used:
    -R
    |If source_file designates a directory, the directory will be deleted with all its files and sub-directories.
    
    -f
    |Remove files without prompting for confirmation, regardless of the file''s permissions.
    |If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
    |The -f option overrides any previous -i options.
    
    -i
    |Request confirmation before attempting to remove each file, regardless of the file's permissions.
    |The -i option overrides any previous -f options.
    
    -v
    |Cause rm to be verbose, showing files as they are removed.
© 2025  mtitek