0

Is it possible even as root one cannot remove directory? What could be the scenarios for directory not getting deleted?

Well nothing wrong with the file system.

There are applications running on the system perfectly.

Trying to delete directory with files and is not a mount/readonly.

Is that something to do with someone has reference to it or is in use not sure?

I am trying this from a shell script and cannot see the error message and need badly to get rid of this directory.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • Do you get an error message when you try to delete a directory, and if so, what is that error message? –  Apr 15 '09 at 21:13

9 Answers9

1

Various possibilities:

  • File system mounted read-only
  • Immutable bit set (system specific)
  • From chaos pessimism: file system damage
  • From MarkR's good thinking: if it isn't empty, you can't delete it. Use ls -A to check for hidden files...
1

NFS normally excludes all write access for root (can be enabled with the no_root_squash mount option (but do not do this unless you absolutely trust absolutely all machines on your network; NFS is sometimes referred to as No File Security, and there is a reason for root being banned by default)).

hlovdal
  • 1,115
  • 11
  • 18
1

Linux has regular permissions (read/write/execute) as well as extended attributes, which are less commonly known.

One of these is the immutable attribute which prevents even root from modifying the file.

The immutable bit is set with chattr +i file and unset with chattr -i file

Another one of these is the append attribute which only allows you to append to the file (not sure how this works with directories)

The append bit is set with chattr +a file and unset with chattr -i file

Brent
  • 22,857
  • 19
  • 70
  • 102
0

A non-empty directory cannot be removed with rmdir even if you're root. Also any other general problem such as readonly file system, io error etc.

0

To rm a directory that contains something inside of it, you have to do a recursive remove. On my ArchLinux machine it would be $ rm -rf /path/to/dir.

Be careful, very careful.

$ rm -rf / your system and bye bye hd without any warnings.

0

Hum... OK, a few basic cases, some of them having been mentioned (hence the community wiki flag):

  • you are using rm without the -r arg

    rm -r directory
  • you are trying to delete from a readonly filesystem

    mount -o remount,rw /mount/point 
  • you are trying to delete from an NFS partition with root-squash

    (nothing you can do here, unless you are allowed to change the settings on the NFS server)

  • you are trying to delete from a read-only media (e.g. disk with the read-only pin set, mmc with lock on, etc...)

    Change the physical protection (may need a reboot)

0

Removing the directory . does not work:

$ sudo rm -rf .
rm: cannot remove directory `.'

Click here to see how to delete the current working directory

0

Here are a couple things that come to mind:

  1. The directory or files within it are in use - you can use lsof (or something similar) to see if anyone has an open handle to something you're trying to delete
  2. The directory or files within it has special characters that need to be escaped to delete
  3. The directory or files within it has spaces that need to be escaped to delete
  4. The script is currently running in the directory you're trying to delete
Milner
  • 935
  • 7
  • 17
-1

File system damage.

chaos
  • 7,483
  • 4
  • 34
  • 49