why doesn't this work I am trying to change all files to 644 abd all -d to 755:
find . -type f -exec chmod 644 {} ;
i get: find: missing argument to `-exec' thanks
Piping to xargs is a dirty way of doing that which can be done inside of find.
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
You can be even more controlling with other options, such as:
find . -type d -user harry -exec chown daisy {} \;
You can do some very cool things with find and you can do some very dangerous things too. Have a look at "man find", it's long but is worth a quick read. And, as always remember:
find . -type f -exec chmod 0644 {} +
which works essentially the same as the xargs method, building one command line. (The \ above is only to escape the semicolon.)
Aug 2, 2016 at 15:49
find . -type d -exec chmod 0755 {} \; && find . -type f -exec chmod 0644 {} \;
Dec 29, 2017 at 11:18
A good alternative is this:
find . -type f | xargs chmod -v 644
and for directories:
find . -type d | xargs chmod -v 755
and to be more explicit:
find . -type f | xargs -I{} chmod -v 644 {}
I need this so often that I created a function in my ~/.bashrc
file:
chmodf() {
find $2 -type f -exec chmod $1 {} \;
}
chmodd() {
find $2 -type d -exec chmod $1 {} \;
}
Now I can use these shortcuts:
chmodd 0775 .
chmodf 0664 .
\;
not with;
alone.-exec
is treated as its argument. If you had a bare;
it would be treated as a terminator for the entirefind
, but really you need to terminate theexec
, so it must be escaped as a part of the argument string.