10

I have done

chmod -R 644 .

inside the directory dir

My user's permissions are drw-r--r-- and i'm the owner of the directory

When trying chmod 755 dir, error is popped

chmod: changing permissions of dir Operation not permitted

The same error is popped when doing ls even as root

How to change permission back to 755 and allow its deletion and modification?

10

from the level above dir:

chmod -R a+x *dir*

to give all users (a) execute permission to all subdirectories and files (+x) or:

chmod -R a+X *dir*

to give all users execute permission to all subdirectories only (+X)

4
  • Coincidently I didn't know that you selectively ignore files by using capital X until i started reading up to give you an answer! – Stephen Mason Dec 8 '16 at 12:06
  • Haha, my bad! I'm still waking up – Stephen Mason Dec 8 '16 at 12:16
  • This gives execute permissions to all below dir to all users. You may not want that. There is another answer here which gives it only to directories (find dir -type d -exec ...). IMHO that is a better solution. – Sybille Peters Oct 2 '20 at 15:30
  • For me, the problem was just preceding the command with sudo. Trivial, but should be stated. – Gulzar Oct 6 '20 at 6:29
3

Since you've broken a tree of directory permissions with chmod -R you need to fix them all up. Run this from the directory above dir:

find dir -type d -exec chmod u=rwx,go=rx {} +
find dir \! -type d -exec chmod u=rw,go=r {} +

In case you're wondering, you need the x permission to access a directory. You need rx to be able to read it.

For those with a modern (GNU) version of chmod you may be able to do this all in one step. Symbolically this equates to "everyone (group/other) has the same as the owner, but remove write permissions from group/other"

chmod -R a=u,go-w dir
3
  • Can you explain what's with the '\!'? The rest looks familiar. – Sybille Peters Oct 2 '20 at 15:31
  • @SybillePeters the ! means not. It is a special character for some shells, and so needs to be single-quoted or escaped with a backslash so that the shell doesn't try to process it. – roaima Oct 2 '20 at 15:42
  • Of course! It's obvious now. Thanks. – Sybille Peters Oct 2 '20 at 18:44
0

enter image description hereHello, I think I have a solution to your problem. Here is the problem:

chmod 777

You did not put sudo so try putting sudo in like this:

sudo chmod 777

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.