Link to home
Avatar of hankknight
hankknightFlag for Canada

asked on

Changing ownership when extracting tar

Hello.

I use the following to extract files:
      tar -xvf

The problem is that my files were tarred from a place where a owner user was called "olduser" and only that owner had permissions over most of the files.

"olduser" does not exist on my new box, it has been replaced with the owner of "newuser"

How can I extract the files, but at the same time replace all ownership from "olduser" to "newuser" ?
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

su to "newuser" then do the extract. Only root has the ability to change usernames, so in this case you do *not* want to have an EUID (effective User Id) of root.
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of noci
noci

on gnu tar you could just add the

"--owner USER" to the tar command.

Is your problem that you've already done the restore and now the ownerships are wrong?
In that case, as root do:
   cd ~"newuser"; chown -R "newuser" .
Then all the files in the "newuser" tree will be owned by "newuser"
Try doing

tar -zxvf filename.tar.gz | xargs chown userid.userid
No actually I think you'll have to filter that but you get the idea?