chown only where needed / speedup chown
5,304
use the find
command, like:
find /folder_with_lots_of_files -not -user someuser -execdir chown someuser {} \+
Related videos on Youtube
Comments
-
rubo77 almost 2 years
On a folder with millions of files this can take quite a long time:
chown someuser -Rf /folder_with_lots_of_files/
How can I speed this up if 99.9% of those files already belong to
someuser
? -
Rabin over 8 yearshow is it different from running
chown -R
? isn'tfind
need to read the file owner as well ? -
steve over 8 years
chown -R
blindly attempts to update the ownership of every file. The find approach only issues achown
where truly needed. May be worth tryingxargs
too, so that a single chown process is issued for, say, every 15 files. -
PSkocik over 8 yearsBut it'll still have to
stat
each file in the tree and that shouldn't be (?) any cheaper that an attempt atchown
. I thinkfind
with-prune
(with-exec ... \+
) might help (if there's a criterion for pruning a subtree that the OP can use). -
PSkocik over 8 yearsInteresting. This does appear faster. Recursively
chown
ing the kernel tree takes me about200ms
of sys time. Thefind
approach takes about100
. -
PSkocik over 8 yearsNow I realize chmod has to stat echo node to traverse the tree. That should explain the doubled sys time -- it needs to both
stat
andchown
and both syscalls should be quick, with the syscall overhead dominating.