Bash tip

Recursively changing the permissions of a directory structure:
find . -type d -exec chmod o+x {} \;

I’ve always found that the find syntax is quite cryptic yet very powerful. Small explanation:

  • find . : start finding in current dir
  • -type d: only directories!
  • -exec chmod o+x {} \;: this is an interesting one. It’s obvious it’s about executing some command =) but what about the braces and the semicolon? The semicolon is just the end delimiter for the exec command and to ensure it does not get interpreted by your shell, it is escaped. The {} is simply a variable indicating one result from the find query, in our case, a subdirectory. Of course, the exec command itself can be anything, here it’s a permission change.

Published by

Leave a Reply

Your email address will not be published.