I have a tar archive containing two owners, 1000 and 0 :

$ tar tfvz archive.tgz
drwxr-xr-x 1000/1000         main/
drwxr-xr-x 0/0               main/root_dir/
drwxr-xr-x 0/0               main/root_dir/home/
-rw-r--r-- 1000/1000         main/root_dir/home/file

Is there a simple way to change ownership only on directories/files with owner 1000 ? Those with owner 0 must stay unchanged.

I didn't find any options in tar or find that select a specific owner, for example tar --no-same-owner change all owners, not only owner 1000 (I extract archive with sudo tar xfz archive.tgz to allow creation of root (0) directories/files).


You can use find's uid switch to do this after you have extracted the files

find /path/to/files -uid 1000 -exec chown newuid:newgid {} +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.