LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-11-2004, 11:23 PM   #1
davidas
Member
 
Registered: Mar 2004
Distribution: Debian 'Sarge'
Posts: 168

Rep: Reputation: 30
Why doesn't "cp -p <file>" copy <file> and preserve ownership?


I have this file in my home directory, created by root:

david@xdavid:~/test$ ls -l
total 0
-rw-r--r-- 1 root root 0 Apr 12 20:20 rootfile

Then I copied the file as a normal user to another file called usrfile, with the -p option:

david@xdavid:~/test$ cp -p rootfile usrfile

However, even with -p option, the ownership of the file is still changed to david. Should it be preserved as root?

david@xdavid:~/test$ ls -l
total 0
-rw-r--r-- 1 root root 0 Apr 12 20:20 rootfile
-rw-r--r-- 1 david david 0 Apr 12 20:20 usrfile

Thanks
 
Old 04-11-2004, 11:42 PM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
no because david != root. you are not root, nor are you in the root group, so there's no way for you to save a file with root as the owner and/or group. nor is there a way as david to change the owner and/or group with chown and/or chgrp. if you wanted it to preserve the owner and group of the file, you need to do the copy as root.
 
Old 04-12-2004, 01:12 AM   #3
davidas
Member
 
Registered: Mar 2004
Distribution: Debian 'Sarge'
Posts: 168

Original Poster
Rep: Reputation: 30
A file created by a normal user "jack" will get its ownership preserved when the root copied the file with the '-p' arguement. However, when another normal user "peter" copied the file with the '-p' arguement, the file's ownership will get changed to "peter".

It seems that the '-p' arguement is only applicable to root.

Am I right to conclude that?

Thanks

Quote:
Originally posted by megaspaz
no because david != root. you are not root, nor are you in the root group, so there's no way for you to save a file with root as the owner and/or group. nor is there a way as david to change the owner and/or group with chown and/or chgrp. if you wanted it to preserve the owner and group of the file, you need to do the copy as root.
 
Old 04-12-2004, 01:38 AM   #4
strikeforce
Member
 
Registered: Jan 2004
Posts: 74

Rep: Reputation: 15
It also depending on the settins will in some folders receive the group permissions or owner permissions for a file created in that folder. e.g. SUID or GUID. Have a look at that as well it depends on a number of things and is and will not be black and white because of all the different variables.
 
Old 04-12-2004, 03:21 AM   #5
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by davidas
A file created by a normal user "jack" will get its ownership preserved when the root copied the file with the '-p' arguement. However, when another normal user "peter" copied the file with the '-p' arguement, the file's ownership will get changed to "peter".

It seems that the '-p' arguement is only applicable to root.

Am I right to conclude that?

Thanks
no you are not right to conclude that. the -p argument works for all users in the constraint of that users abilities on the system. generally non-root users will be able to preserve ownership of their files that they own and are owned by a group that the specific non-root user belongs to. they cannot preserve ownership of files owned by other users (albeit, there may be ways around this depending on the suid, guid, and sticky bits). root can preserve the ownership of files owned by different users, because root has full system priveledges. but joe_schmoe can not preserve the ownership of files owned by root or files owned by billy, etc. depending on where the file will be copied to, joe_schmoe can only preserve file ownership of files owned by joe_schmoe and owned by a group joe_schmoe belongs to.

Last edited by megaspaz; 04-12-2004 at 03:36 AM.
 
Old 04-12-2004, 05:44 AM   #6
strikeforce
Member
 
Registered: Jan 2004
Posts: 74

Rep: Reputation: 15
Thats probably the best explanation I've heard and should really explain it. In comparison windows separate things out into different folders and such where as linux actually uses file permissions more so than windows maybe its the users but then again maybe its just what is stressed.

Linux 'forces' you to be more secure than windows thats probably the biggest difference that I noticed since I switched across I can't just do anything even if it is my computer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"bad interpreter : no such file or directory" when configure "flex" acer_peri Linux - Software 10 11-10-2010 01:19 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
preserve file ownership with the "zip" command? zovres Linux - General 2 11-25-2004 09:01 PM
Cannot "Copy To" .jpg file to wallpaper folder LeanPudLou Suse/Novell 5 11-08-2004 08:24 AM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM


All times are GMT -5. The time now is 11:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration