hankknight
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" ?
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" ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
on gnu tar you could just add the
"--owner USER" to the tar command.
"--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"
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
tar -zxvf filename.tar.gz | xargs chown userid.userid
No actually I think you'll have to filter that but you get the idea?