3

I have a directory, that I cannot delete with rmdir. I get always a permission denied error. But when list the directory (with ls -l) I get this:

drwxrwxrwx  2 user user 4096 Aug 28 09:34 directory

stat gives me that:

  File: `directory/'
  Size: 4096            Blocks: 16         IO Block: 32768  directory
Device: 12h/18d Inode: 102368771   Links: 2
Access: (0777/drwxrwxrwx)  Uid: ( 1000/  user)   Gid: ( 1000/  user)
Access: 2015-08-31 03:00:20.630000002 +0200
Modify: 2015-08-28 09:34:16.772930001 +0200
Change: 2015-08-31 12:25:04.920000000 +0200

So how delete that directory.

  • 1
    What are the permissions of its parent? – Celada Aug 31 '15 at 10:36
5

If you are trying to delete a directory foo/bar/, the permissions of bar isn't the relevant factor. Removing the name bar from directory foo is a modification of foo. So you need write permissions on foo.

In your case, check the current directory's permissions with ls -ld .

You might find this answer to "why is rm allowed to delete a file under ownership of a different user?" enlightening.

1

Another possibility is that the "immutable bit" is set on this directory. You can check it with ls -d <directory>. Permissions set with chattr won't show up on the stat output:

stephan@x230 ~ % stat testdir
  File: ‘testdir’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d  Inode: 13713629    Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ stephan)   Gid: ( 1000/ stephan)
Access: 2015-08-31 14:05:49.957299346 +0200
Modify: 2015-08-31 14:05:25.657267292 +0200
Change: 2015-08-31 14:05:42.685289494 +0200
 Birth: -


stephan@x230 ~ % lsattr -d testdir
----i--------e-- testdir`

You have to be root to remove the immutable bit: chattr -i testdir

1

Inside that dir must be a file without the needed permissions. Try changing the owner recursively to all the dir and then remove it.

$ sudo chown -R user:user dir/
$ rm -rf dir/

From man rm

-r, -R, --recursive
  remove directories and their contents recursively
-f, --force
          ignore nonexistent files, never prompt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.