I want to find a file in an unknown directory and then chmod it. Could you help with that please? So far I wrote find . -type f -name ".pdf" chmod {};


the man page of find command says that in order to execute a command (in this case chmod) to matching file the command need to be specified using -exec parameter

find . -type f -name "*.pdf" -exec chmod 744 {} \;
|improve this answer|||||
  • Thank you it worked! However, wouldn't this change the permission for all the .pdf files that there are in my computer? I only want it to change the permission for the files inside the mainDir directory/inside the random subdirectory that the user chooses. Cheers – Jim6834 Oct 20 '19 at 11:14
  • @Alec Find command will search for files in all subfolder in the current directory. If you want, you can change the '.' to any directory you want. For example find /home/user/app -type f -name "*.pdf" -exec chmod 744 {} \; will search for all PDF in the /home/user/app directory and it's subdirectory – jrandiny Oct 20 '19 at 11:19
  • @Jim6834 please add the information from your first comment above to your question – steeldriver Oct 20 '19 at 13:44

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.