Bash – chown: missing operand after ‘root:users’

bashchowndebianfind

I try to change owner to root:users recursively below a directory, if owner is other than root:users.

cd /dir/
find . \( ! -user root -o ! -group users \) -print0 | xargs -0 chown -vc root:users 

I get error:

chown: missing operand after ‘root:users’
Try 'chown --help' for more information.

Why I get the error?
How can I fix it?

Best Answer

Use the recursive switch on chown:

chown -R root:users dir

And that should do it.

More to why you have an error: if the find command doesn't find any files, then chown will be executed without an operand at the end, which generates this error.

If you are really intent on sticking with your original command format, you can add the -r switch to xargs and it should get rid of the error when no files are found.

Related Question