How Do You Delete a Directory on Linux Server That Is Not Easily Deleted?

Problem scenario
You are trying to remove a directory.  When you run a "sudo rm -rf" command you get this error:

rm: cannot remove '/path/to/': Device or resource busy

When you run a "sudo umount /path/to/" command you get this error:

"umount.nfs: device is busy"

What should you do to eliminate the directory?

Solution
1.  Is the "/path/to/" in the "sudo umount" command identical to the path in the error message?  If so, skip to step #2.  If not, remember that if you get an error like this "'/path/to/subdirectoryname': Device or resource busy", then you need to try the umount command *with* the subdirectory.  The root cause of this is you are trying to umount a parent directory of a subdirectory that is mounted.

2.  If the directory is not unmounting and you are using the "sudo umount" command, run these two commands:  

sudo umount -f -l /path/to

# The -f flag is for force.  The -l flag will clean up references to the file system.  Using these two flags at the same time is recommended by various Linux experts when a directory will not unmount as it normally should.

sudo rm -rf /path/to

Leave a comment

Your email address will not be published.