find . a* -exec chmod o+r {} \;
find . *d -exec chmod o+x {} \;

I want to give o+r to all files that start with "a" and o+x to all files that end with "d", but these lines seem to affect all files under the directory.


Put a* and d* under quotes, so that shell would not expand them,and also add -name keyword. If you only want to search for files and not also directories for example then add -type f.

find . -name 'a*' -type f -exec chmod o+r {} \;
find . -name '*d' -type f -exec chmod o+x {} \;

If you want to change only in current directory and not subdirectories, add -maxdepth option

find . -maxdepth 1 -name 'a*' -type f -exec chmod o+r {} \;
find . -maxdepth 1 -name '*d' -type f -exec chmod o+x {} \;

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.