Q:

How to Delete a Non-empty Directory from Terminal in Ubuntu

0

How to Delete a Non-empty Directory from Terminal in Ubuntu

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the rm Command

You can use the following command to delete or remove all files and folders contained in a directory.

sudo rm -rf /path/to/folderName

For example, if your current working directory is /var/www and you want to delete the directory named sample inside of it, you can simply use the command:

sudo rm -rf sample

Or, if you prefer absolute path you can run the following command.

sudo rm -rf /var/www/sample

Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.

The options have the following meanings:

  • -r : Recursive remove. rm will recursively remove directory and everything under it.
  • -f : Forced remove. Unwritable files are forcibly removed. By default, rm will ask permission before removing unwritable files. Use this option with care.

Additionally, for interactive removal you can use the option -i with the rm command (i.e. -rfi). With this option rm will ask permission before removing anything.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ubuntu / Linux Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Get a List of All Installed Packages on Ubu... >>
<< How to Install Updates Via Command Line on Ubuntu...