1826454 Members
3241 Online
109692 Solutions
New Discussion

preserve the ownership

 
Cheung_2
Frequent Advisor

preserve the ownership

After the user zip the file , then the owner of the zip file will be changed , how to preserve the owership ? thx

host//tmp> ll abc.prn
-rwxrwxrwx userA abc.prn
host//tmp> whoami
host//tmp> userB
host//tmp> gzip abc.prn
gzip: abc.prn: Operation not permitted
host//tmp> ll abc.prn*
host//tmp> -rwxrwxrwx userA abc.prn
-rwxrwxrwx userB abc.prn.gz
How to let the owner of the file "abc.prn.gz" is userA (except change it by root) ? thx
Andy
8 REPLIES 8
Sridhar Bhaskarla
Honored Contributor

Re: preserve the ownership

Is there any reason why you don't want "userB" to change the ownership of the file to "userA"?

As long as userB owns the file, he can change the ownership of the file to anything.

$whoami
userB
$ll abc.*.gz
-rwxrwxrwx userB abc.prn.gz
$chown userA abc.prn.gz

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Patrick Wallek
Honored Contributor

Re: preserve the ownership

I don't think there is a way to retain the ownership.

When you gzip, or compress, a file, you are creating a NEW file. The gzip process reads the contents of the non-compressed file, pushes the data through the compression routines and writes it out to a new file.

When you create the new file, it will be owned by the user doing the gzip. The only way to have the owner be userA would be to do a 'chown userA abc.prn.gz' after the file is gzip'ed.
S.K. Chan
Honored Contributor

Re: preserve the ownership

The rule (like mentioned by others) is ..
1- Ownership of a file can only be changed by the owner of the file or by root.
To be consistent, as user "userB" make a copy of the file first so that "userB" owns that copied file and then gzip it.
T G Manikandan
Honored Contributor

Re: preserve the ownership

When you unzip a file using a user it creates a new file with that username as owner.

Log in as Userb ans gzip the file.
T G Manikandan
Honored Contributor

Re: preserve the ownership

check this unzip utility from hp porting center.

check the -X option.This should be what you are looking for.

http://hpux.cs.utah.edu/hppd/hpux/Misc/unzip-5.50/
T G Manikandan
Honored Contributor

Re: preserve the ownership

sorry unzip is for .zip extension files.

Cheung_2
Frequent Advisor

Re: preserve the ownership

Hi all,

Thanks all suggestion , I tried I can run chown to change owner to original owner on UNIX box , but can't do the same thing at Linux , can suggest how to do it on Linux ? thx.
Andy
T G Manikandan
Honored Contributor

Re: preserve the ownership

chown own is for changing the ownership of a file and it can be executed only by the owner of the file or root.

Linux also has the same policy.
Use root to change the ownership or be the owner of the file.

Revert