chmod files differently to directories

10 June 2005   10 comments   Linux

Mind That Age!

This blog post is 12 years old! Most likely, it's content is outdated. Especially if it's technical.

Powered by Fusion×

Jan gave me the following piece of advice that I feel I have to write about to help me understand it. What I wanted to do was to set all file to 644 which basically means that the owner can write to it unlike any other losers and it can't be executed. The problem with doing a recursive chmod like this on all files is that you don't want to remove the executability of directories otherwise you won't be able to do useful stuff like ls inside the directory. The trick is to use the +X option. This is what I did:

$ sudo chmod -R 644 IssueTrackerProduct
$ sudo chmod -R +X IssueTrackerProduct

According to the man pages:

" execute only if the file is a direc- tory or already has execute permission for some user (X)"

I can't find a better reference about it now with Google because whatever I search for seems to always be talking about the little +x which has a very different meaning.


lite mer hårdrock, lite mindre tänk. bärs bengtsson, bärs för guds skull.
baba o'riley med the who. ladda hem nu sa jag. hv! annars phantom of the opera med järn maiden. för helvete bengtsson!
I wonder if my comments actually are born on your www. så att säga. But let me say jeans and you will understand. Do i make myself clear or am i ruin your www. www=world wide web. jeanskalsong with a kapuschong. balle.
Peter Bengtsson
He he. Klart jag förstår vad min tjocke gamle jeanskompis har att säga. Syns om en vecka typ.
with ruin i mean destroy. sorry ich cant bend it right. Henjeby.
Thanks, I searched Google for this exact issue, and found your site. Thanks for posting it, I can now open up my directories to patrol agents, but not allow them to run files within. Perfect!
If you do it in one command you dont need to be root, you can be just the owner of the dir:
chmod -R a-x+X yourdir
Also, if you don't want 'other' from accessing...

chmod 640 -R directory
chmod ug+X -R directory

(Posting for my own reference. Thanks for the +X tip! I accidently set all my personal files to executables!)
find . -type f -exec chmod 644 {} \;
very nice advice, thanks
Thank you for posting a comment

Your email will never ever be published

Related posts

Good design examples for a non-blog 09 June 2005
My trade salary has gone down, apparently 12 June 2005
How to use premailer as a command line script 13 July 2012
Find largest directories with du -k 29 December 2006