3

I recently noticed that all of the files in my ~/Documents were somehow incorrectly given executable status. This proved annoying as trying to opening any file gave me a message box saying it was executable. I tried doing a recursive chmod like:

chmod -R 644 ~/Documents

Unfortunately, this made the whole Documents folder inaccessible. What went wrong?

  • You can't enter into folders that you don't have execute permissions to. –  Mar 20 '24 at 15:21

1 Answers1

10

You need to have the execute bit set on a directory to allow the affected user to enter it and access files and directories inside, and you've removed it (your command removes the execute bit from both the files and the folders). There is information about this here. The following command should fix it:

find ~/Documents -type d -exec chmod a+x {} +
Chris Down
  • 125,559
  • 25
  • 270
  • 266
  • Yeah. I get it now. Directories always need executable bit set. Thanks. – Bernhard Heijstek Nov 15 '11 at 21:52
  • 1
    @BernhardHeijstek: Almost. It can make sense for a directory not to have execute (actually) search permission. If a directory has 644 permission, for example, you can refer to files under that directory only if you already know their names. But I've hardly ever used that feature myself. – Keith Thompson Nov 15 '11 at 22:01
  • Isn't that read, not execute, that prevents "searching"? – janmoesen Nov 15 '11 at 22:22
  • @janmoesen That would depend on what your definition of "searching" is. – Chris Down Nov 15 '11 at 22:31
  • @Chris thanks for sharing this info. i believe i removed the executable bit on my home folder a long time ago, couldn't figure out what went wrong. only now i'm realizing what i did... – ixtmixilix Nov 15 '11 at 22:32
  • @BernhardHeijstek: Hmm, experiment shows that I might have gotten that wrong -- or maybe my system is behaving strangely. – Keith Thompson Nov 15 '11 at 23:17
  • @ChrisDown: I was referring to Keith's suggestion to use 644 and his choice of "search". What I meant, was: you should set -r to prevent people from reading the contents of the directory, rather than -x. If you set -x, access is not possible at all. – janmoesen Nov 16 '11 at 09:47