Unix / Linux: Remove Nonempty Directory Command

I am trying to remove a directory called /opt/source/httpd with the rm command. I am greeted with the following message:

rmdir: failed to remove `/opt/source/httpd’: Directory not empty

How do I delete directory called /opt/source/httpd under Linux or Unix operating systems?

The rmdir command Remove the DIRECTORY(ies), if they are empty. The syntax is:

rmdir dirName
rmdir [optipns] dirName

The rmdir utility removes the directory entry specified by each directory argument, provided it is empty. To remove non-empty directory use the rm command as follows (warning: the following command can delete all the files and its subdirectories specified by each directory argument)

rm -rf /path/to/dir
rm -rf /opt/source/httpd

If you can not use rm -rf command, try the following commands:

cd /opt/source/httpd
### Delete all files from all directories ### 
find . -name * -type f -exec rm {} ;
### Delete all sub-directories ###
find . -name * -type d -exec rmdir {} ;
### Finally delete /opt/source/httpd ###
cd ~ 
rmdir /opt/source/httpd

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts