Whenever you try to remove any non empty directory in linux system responds with “rmdir directory not empty” error. In this article we will be discussing how to remove “rmdir directory not empty” error in Linux.
Problem : rmdir directory not empty Error
In my system I am trying to remove non empty directory called “myfolder” inside /tmp filesy-system. System responds with below error message.
[root@rhel tmp]# pwd /tmp [root@rhel tmp]# rmdir myfolder/ rmdir: failed to remove ‘myfolder/’: Directory not empty [root@rhel tmp]#
Solution: Removing non empty directory
In such case you need to use rm command along with rf (recursive and forcefully) flag in order to remove non empty directory.
Syntax:
rm -rf <dir> rm -rf <full path of directory>
Here “r” indicates recursive flag and “f” option indicates forcefully flag.
So in our example , in order to remove non empty directory called “myfolder” we need to use below rm command:
[root@rhel tmp]# ll total 4 drwx---rwx 2 manmohan manmohan 4096 Jan 25 07:33 myfolder [root@rhel tmp]# rm -rf myfolder/ [root@rhel tmp]# ls [root@rhel tmp]# pwd /tmp [root@rhel tmp]#
In case you are getting permission denied error please follow my article to resolve this issue.
Download Free book
Get your free copy of Linux command line Cheat Sheet!!!!