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
Delete Files using
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
rm -f <file1> <file2>
To get a confirmation dialogue for each file to be deleted, use the
rm -i <file1> <file2>
Delete Folders using
To delete empty folders, we use command
To delete a non-empty folder, along with files and folders inside it recursively, we use
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.