Skip to main content

The rm command attempts to remove the non-directory type files specified on the command line. If the permissions of the file do not permit writing, and the standard input device is a terminal, the user is prompted (on the standard error output) for confirmation.

# To delete files "one.txt", "two.txt", and "three.txt" from the current directory:
rm one.txt two.txt three.txt

# To delete all files in the current directory:
# WARNING Files can not be undeleted so be careful with the following command.
rm *

# To delete all files from the "$HOME/jon" directory:
rm $HOME/jon/*

# To recursively delete all files and sub-directories from "$HOME/jon/"
rm -rf $HOME/jon/*

# To delete files interactively (prompt for confirm):
rm -i *

# To delete all *.docx files (files ending with .docx extensions):
rm *.docx

# To delete all files in the current directory that have the string music in their file name:
rm *music*

# To delete all files that begin with a lower case letter z:
rm z*

# To delete all files in the current directory whose names, inclusive of any
# extensions, are exactly three characters in length:
rm ???

# The following would tell the rm command to delete all files in the current
# directory that begin with the letter z and are six characters in length:
rm z?????

# To delete all files in the current directory that have a two-character
# filename extension:
rm *.??

# To delete all files in the current directory that have an A, B and/or C in
# them:
rm *[ABC]*

# To delete all files that have digits (zero to nine) in them i.e. at least one
# numeral in filename:
rm *[0-9]*

# To delete all files had an extension that begins with c or h:
rm *.[ch]*

# To delete all filenames in the current directory that consist of images
# followed by a two-digit number:
rm images[0-9][0-9].png

# To remove files in verbose mode, printing a message for each removed file:
rm -v path/to/folder/*