Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 {} +
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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