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?

  • 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


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.

  • 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

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.