Tuesday, 12 November 2013

How to delete a non-empty directory in terminal?



Suppose you have directory "lampp"

If you type:
rmdir lampp
This error comes up:
rmdir: failed to remove `lampp': Directory not empty

Use rm -rf lampp it delete all files and folders contains in lampp directory.


Explanation:
There are lot of way to delete a directory through CLI mode. It depend which way you are conformable.
rm -rvf /path/to/directory
  • -r = remove directories and their contents recursively
  • -v = explain what is being done
  • -f = ignore nonexistent files, never prompt
If you are new in Linux, use man page's of commands (man rm) for more option and more accuracy.
rm -r lampp
However, you need to be careful with this command, as it makes it easy to accidentally delete a lot more than you intended.
It is a good idea to always double-check which directory you're in, and whether you typed the command correctly, before pressing Enter.
Safer version
rm -r -i lampp
Adding -i makes it a little safer, because it will prompt you on every deletion. However, if you are deleting many files this could quickly get annoying.
 


Share:

No comments:

Post a Comment