rm

Remove files (delete/unlink)

Syntax
      rm [options]... file...

Options

   -f, --force
       ignore nonexistent files, never prompt 
   -i
       Prompt before every removal 
   -I
       Prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes 
   --interactive[=WHEN]
       Prompt according to WHEN: never, once (-I), or always (-i). Without WHEN, prompt always 
   --one-file-system
       When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument 
   --no-preserve-root
       Do not treat '/' specially 
   --preserve-root
       Do not remove '/' (default) 
   -r, -R, --recursive
       Remove directories and their contents recursively 
   -v, --verbose
       Explain what is being done 
   --help
       Display this help and exit 
   --version
       Output version information and exit

To remove a file you must have write permission on the file and the folder where it is stored. The OWNER of a file does not need rw permissions in order to rm it.

By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents.

Note that if you use rm to remove a file, it is usually possible to recover the contents of that file. If you want more assurance that the contents are truly unrecoverable, consider using shred.

Undeletable files

The rm command accepts the -- option which will cause it to stop processing flag options from that point forward. This allows the removal of file names that begin with a dash -.
rm -- -filename
Alternatively use an absolute or relative path reference.
rm /home/user/-filename
rm ./-filename

To delete a file with non-printable characters in the name: 'bad file name' Use the shell wildcard "?" for each character

rm bad?file?name

Older file systems such as ext2fs, perform badly for massive bulk deletes. The newer ext3fs doesn't have this performance problem.
To remove a very large number of files from a directory it can be quicker to rm them one at a time in a loop:

find my_dir -type f | while read -r; do rm -v "$REPLY"; sleep 0.2; done

"It devoured my paper, it was a really good paper" ~ Ellen Feiss

Related:

ls - List information about files
rmdir - Remove folder(s)
Equivalent Windows command: DEL - Delete one or more files


© Copyright SS64.com 1999-2013
Some rights reserved