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?
use the find command, like:
find /folder_with_lots_of_files -not -user someuser -execdir chown someuser {} \+
chown -R? isn'tfindneed to read the file owner as well ? – Rabin Nov 24 '15 at 22:57chown -Rblindly attempts to update the ownership of every file. The find approach only issues achownwhere truly needed. May be worth tryingxargstoo, so that a single chown process is issued for, say, every 15 files. – steve Nov 24 '15 at 22:59stateach file in the tree and that shouldn't be (?) any cheaper that an attempt atchown. I thinkfindwith-prune(with-exec ... \+) might help (if there's a criterion for pruning a subtree that the OP can use). – Petr Skocik Nov 24 '15 at 23:02chowning the kernel tree takes me about200msof sys time. Thefindapproach takes about100. – Petr Skocik Nov 24 '15 at 23:12findhas tostateach file to traverse the tree (to distinguish directories), and if the number ofchowncalls are relatively small, that will run faster. It would not run faster if the fraction were not small, due to overhead of running the-execto make subprocesses. – Thomas Dickey Nov 24 '15 at 23:16statandchownand both syscalls should be quick, with the syscall overhead dominating. – Petr Skocik Nov 24 '15 at 23:28chown user:group? Can we modify this command to accommodate it? – Prasannjeet Singh Jan 23 '23 at 18:40chown someuserabove usechown someuser:group. – gogoud Feb 23 '23 at 08:02