Most of us using Ubuntu know that a directory can be easily deleted using the “rm” command, but this works only for empty directories. If you try the same command “rm folderName” with a folder containing files/folders, you will end up getting an error – “rm: failed to remove ‘folderName’: Directory not empty”. This is because the command only works for empty folders.
An addition of a simple “-r” can solve your problem. This command recursively checks and removes all the files and directories within the directory in question. The command below will remove a non empty directory in Ubuntu.
rm -r folderName
The above command will ask for your confirmation to delete the directory. If you are an expert user and you are absolutely sure that the directory you typed is the one you want to delete, then you can use the command given below instead. This will not ask for confirmation and will delete the directory straight-away.
rm -rf folderName
If you are a beginner and you want to confirm each and every file individually before deletion, then you should use the following command.
rm -r -i folderName
The command above is the safest one. It will keep you from accidentally deleting files you don’t intend to.