Linux Commands | File Management | rm Delete Files/Directories

rm

rm is a command used to delete files or directories.

rm is short for “remove”.

rm Syntax

rm (options) [file or directory name to delete]

rm Options

Option Description
-r Deletes regular files or directories, including subdirectories and files under the target path.
-i Asks for confirmation with y/n before deleting.
-f Forces deletion without asking for confirmation.
-rf Forces deletion of directories and their contents without asking for confirmation.

When deleting directories, rm -rf is commonly used.

rm Examples

Delete a file

rm test

Ask for confirmation before deleting a file

rm -i test

Force-delete a file without confirmation

rm -f test

Delete an empty directory

rm -r testdir

Force-delete a directory even if files exist inside it

rm -rf testdir