Example Uses of the Linux Command rm

Delete files from the Linux command line

Illustration of a command line in Linux

Getty Images

The "rm" command is used for deleting a file or directory (folder). The command name "rm" is derived from "remove".

The rm command doesn't have a trash/recycling bin. Once you delete something with rm, it's gone permanently.

To remove the file "accounts.txt" in the current directory you would type:

rm accounts.txt
Linux remove file

Removing a directory requires an additional option, the '-r' switch. It tells your computer to remove files recursively, meaning you'll delete your the folder and everything in it. To remove a folder in your current directory, run:

rm -r folder
Linux remove folder

In order to delete a file that is not in the current directory, you can specify the full path. For example,

rm /home/jdoe/cases/info.txt

You can selectively delete a subset of files using the wildcard character "*". The example below would delete all files that end in ".txt" in your current directory.

 rm *.txt
Linux RM with wildcard

Think twice before using "rm". The system may immediately remove the specified files without giving you chance to confirm. And there is no "garbage can" where you can go to retrieve deleted items.