How to delete a Non-empty directory using Terminal on Ubuntu/Linux machine?
Use the rm
command to remove or delete a directory, that contains files and folders.
The word rm
stands for Remove.
Syntax
Here is the syntax for removing a directory with the required options.
- The word
rm
stands for remove. - The option
r
makes a Recursive remove, which removes the directory and all its content. - The option
f
makes a Forced remove, which removes even the locked and unwritable files without asking any permission (by default,rm
will ask for permission).
sudo rm -rf dirPath
Use the below command to delete a directory, in the current working directory.
sudo rm -rf sample
Use the below command to delete a directory from anywhere on the machine, using its absolute path.
sudo rm -rf /var/www/sample
Use the below command to delete a directory in interactive mode.
The option i
makes the remove function interactive, which will ask for the user's permission before removing anything.
sudo rm -rfi /var/www/sample