How do I safely delete all files, on Ubuntu Linux, with a specific extension (e.g. .bak
) from current directory and all subfolders simply by using one command-line? I'm afraid to use rm
 because I used it wrong once and now I need advice. Is it possible to perform such action?
How to safely remove specific files on Linux?
To delete any folder and all the sub-folder, use the below command in Ubuntu command line terminal.
Rm – r file name
In the command if you are in the same folder where the file is present, you can use the file name directly. But if you are not in the same folder then correctly specify the path of the file. If you want to delete the files immediately without any confirmation use rm-f file name. This will only delete the files not the sub-directory. In case of rm -i file name, it will prompt for confirmation to delete the file. Once you will confirm it will only delete the file not the sub-directory.
Never use sudo rm-R or sudo rm-r. It will delete all the data of the mounted volume and also all the data in the root directory. If you want to wipe out everything from your system then only use sudo rm-R or sudo rm-r. Also never use sudo rm -f it creates problem to the system by deleting other files which are not intended.