Fix file (644) and directory (775) permissions in Linux easily

A few weeks back I was sorting out the drives on my Linux server and as some of the directories were created through various configurations of Samba by Windows clients the permissions were a bit odd. Some archive files were executable, some directories were rw only for the owner. You get the idea, it was a mess. How do I fix them quickly?

I’d like all the files to be 0644 and directories should be 0775 please. Oh, and I’d like all that done with the minimum of fuss through a Bash shell, with or without a cherry on top.

Luckily I’m not the first person to ask this as user stress_junkie in this thread had an answer:

For directories only do this.
[bash gutter=”false”]find . -type d -exec chmod 775 {} \;[/bash]

For files only do this.
[bash gutter=”false”]find . -type f -exec chmod 664 {} \;[/bash]

There’s also this useful chunk of code to avoid hitting . and .. but I didn’t care about that in my case so the above code worked perfectly:

[bash gutter=”false”]find . -type d -name \* -exec chmod 775 {} \;[/bash]

And finally, user Gethyn pointed out that this command will add execute permissions to directories.

[bash gutter=”false”]chmod -R +X[/bash]

I have a feeling I’ll be coming back to this post in the future, just like I’ve had to check my directory comparison post a couple of times recently.

Author: Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Google+ and Twitter.

5 thoughts on “Fix file (644) and directory (775) permissions in Linux easily”

  1. I ended up having to chown my files also, like so:

    sudo chown -R tom:tom *

    Where the first tom is my username, and the second tom is my group name. After doing that all is as it should be.

Leave a Reply