Automatically changing the permissions of only certain files in subdirectories


I need to change the permission of all files with the following extentions inside of a certain directory to 777:

There are over 200 files in 15 sub-directories.

I have ssh access. How can I change the permissions of all the files in all the subdirectories at once? Thanks!
Who is Participating?
Karl Heinz KremerConnect With a Mentor Commented:
You can also combine the three extensions into one command:
find /path/to/parent -name "*.dat" -print , -name "*.bak" -print , -name "*.lock" -print | xargs chmod 777

Karl Heinz KremerCommented:
Use the find command:

find /path/to/parent -name "*.dat" -print | xargs chmod 777
find /path/to/parent -name "*.bak" -print | xargs chmod 777
find /path/to/parent -name "*.lock" -print | xargs chmod 777
tkalchevConnect With a Mentor Commented:
Or try this one (it is almost equivalent ) :

find /path/to/parent -name "*.dat" -exec chmod 777 {} \; , -name "*.bak" -exec chmod 777 {} \; , -name "*.lock" -exec chmod 777 {} \;
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Karl Heinz KremerCommented:
your solution will be slower: You are forking the chmod command for every single file. The xargs mechanism collects a number of file names and then forks one chmod command for a number of files.
True, but no chance for "argument list too long" error :)
Karl Heinz KremerCommented:
... and for 200 files it does not make a big difference :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.