Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

linux remove directory

on the command line, I am using rm -Rf directoryname and the directory will not remove, says they are not empty.  Does anyone know another way to remove this?
6 Solutions
Kent WSr. Network / Systems AdminCommented:
That command will indeed force removal of a directory and all subdirectories.
There are either immutable files, or a permissions issue.  If you are running this as root, look for immutable files.
Gerwin Jansen, EE MVETopic Advisor Commented:
Can you post the exact error message you're getting?
Could it be that the directory in question is an active mount point or that it contains one or more active mount points (NFS or local, anyway)?

Go to the directory in question and issue "df ." What do you see?

Next, issue "df" alone. Do you see the path to your directory somewhere in a path to a mount point?
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

sudo rm -rf /path/to/dir

Open in new window

Jack_son_Author Commented:
the error message is:  

Unable to remove directory dirname:  Directory is not empty
Kent WSr. Network / Systems AdminCommented:
If you are root, or using su, then there is something other than "regular" files / directories in your target directory.
Look for immutable files, links, mounts, etc. You may have to cd down and remove some directories one at a time until you find the culprit.  Make sure to do an ls -a so you can see hidden files while searching.
Jan SpringerCommented:
rm -rf /directory

will remove the directory and all files underneath if run as root.  if not root, that the user must have permission to remove all of the files and the directory.
1. go  into directory
2. #ls -lah
3. remove if any hidden directory is there
4. check #df -h to see whether it is being used as mount point for any FS.
5. delete if by using #rm -rf /path/to/dir

if still no luck.. try checking #lsof /path/to/dir


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now