Avatar of hankknight
hankknight
Flag 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" ?
LinuxLinux Distributions

Avatar of undefined
Last Comment
Kelly Black

8/22/2022 - Mon
Duncan Roe

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
Tintin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
noci

on gnu tar you could just add the

"--owner USER" to the tar command.

Duncan Roe

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"
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Kelly Black

Try doing

tar -zxvf filename.tar.gz | xargs chown userid.userid
Kelly Black

No actually I think you'll have to filter that but you get the idea?