Linux has many commands for the removal of files and directories. These programs use different kinds of algorithms to delete files from different file systems. In this article, we will see how to delete files and folders from Linux command line using rm and rmdir commands.

Delete Files using rm

Use rm command to remove a single file or multiple files:

rm <filename>
rm <file1> <file2>

If a file is write-protected, the command will prompt for confirmation before deletion. To automatically give affirmative inputs to such prompts, use the -f flag:

rm -f <file1> <file2>

To get a confirmation dialogue for each file to be deleted, use the -i flag:

rm -i <file1> <file2>

Delete Folders using rmdir and rm -r

To delete empty folders, we use command rmdir:

rmdir <folder_name>

To delete a non-empty folder, along with files and folders inside it recursively, we use rm with -r flag:

rm -r <folder_name>

Note that the rm command does not ensure permanent removal of data, i.e., data can still be recovered from the disk using certain data recovery tools.

To make sure your deleted data cannot be recovered, check our post on permanently deleting files and folders in Linux at the link below.

READ: How to Permanently Delete Files in Linux