How To Remove or Delete A Directory In Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-remove-or-delete-a-directory-in-linux/
PINTEREST
PINTEREST
INSTAGRAM

Linux provides different commands in order to remove or delete directories and files. But in some cases this may not work as expected and we can get a message like rmdir: 'dir' Directory no empty which simply means when we try to delete directory with rmdir command it is not completed. In this tutorial we will learn how to remove and delete empty or full directory.

Remove with rm -Rf Command

The most used command to delete directory with its content is rm command. But rm command is not enough without options -Rf . This will force deletion of given directories in a recursive manner. In this example we will delete directory named backup

Remove with Verbose Information

Deleting directory with its children will not provide verbose information by default. But we can print detailed information about operation with verbose option -v like below.

Remove with Verbose Information
Remove with Verbose Information

Remove with Root Privileges

In order to delete a file or directory we need privileges. If the directory is owned by root user and we are not we can not delete directory. So we need to get root privileges with sudo command like below.

Remove with Python

We can also use some python script or commands in order to delete a directory please look following example where we will use os module remove() function.

How To Delete and Remove File and Directory with Python?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-remove-or-delete-a-directory-in-linux/
PINTEREST
PINTEREST
INSTAGRAM
LEARN MORE  Linux Top - Monitor Linux System Resources Cpu, Memory, Network