Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my Linux system, I've got into a situation where there are not write/execute permissions on directories on a mounted drive. As a result, I can't get into a directory before I open its permissions up. This happens every time I mount that drive. The mounting operation is done by a tool under its hood, so I doubt if could modify mount parameters to address this problem.

As a workaround, I am using this find command to modify permissions on directories. I use it repetitively, since it gets one more level of directories on each run.

find . -type d -print0 | xargs -0 -n 1 chmod a+wrx

I am sure there is a better way to do this. I wonder if there is a find option that processes a directory first and then its contents - the opposite of -depth|-d option.

Any tips?

share|improve this question
    
Initially posted at stackoverflow.com/q/12040396/305686 –  Mahesh Aug 20 '12 at 15:36
    
For future reference, it is usually best to ask a moderator to migrate a question you want moved instead of posting a duplicate-copy. It keeps the various sites better organized and helps people find answers more easily that way. –  jw013 Aug 20 '12 at 15:48
    
@jw013 noted, Thanks. –  Mahesh Aug 20 '12 at 20:46

1 Answer 1

up vote 2 down vote accepted

Try:

find . -type d -exec chmod a+rwx {} ';'

This will cause find to execute the chmod before it tries to read the directory rather than trying to generate a list and feed it to xargs.

share|improve this answer
    
Thanks! That did it. Next time I'll put a little more thought on use of -exec versus xargs. –  Mahesh Aug 20 '12 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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