I have a directory structure in which I'd like to change the permissions on all header files. I tried this command:
chmod -R 644 *.h
but it just changed the files in the current directory. Isn't the "-R" supposed to make the command apply to subdirectories as well?
Thanks.
find . -name '*.h' | xargs chmod 644
Thanks for that alternative. But I'm still curious as to why the way I tried it didn't work.
Since you chose to use only the *.h
files, no directories were included in your command, so there are no directories to apply recursion.
Also, if your files contain spaces, that won't work. I think the best way would be
find . -name '*.h' | while read file
do
chmod 644 $file # edit
done
|
Last edited on
That's because each line outputted by find
is read by while
and assigned to the variable file
. If pwd
accepted arguments, you would do
find ~ | while read file; do pwd $file; done
Yes, my mistake.
So shouldn't your example be:
|
find . -name '*.h' | while read file; do chmod 644 $file; done
|
Last edited on
find . -name *.h -execdir chmod 664 '{}' \;
Last edited on