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 11-30-2022, 01:38 PM   #1
csj79
LQ Newbie
 
Registered: Aug 2022
Posts: 17

Rep: Reputation: 0
Difference between cp -a and cp -p


Hello Everyone,

I am trying to see the main difference between cp -a and cp -p. The man pages are a bit confusing to me.

I tested those two commands on my ubuntu system as root and it feels like the end result is the same.

It seems like both cp -a and cp -p preserve the original file permissions, owners and groups and timestamps. I am not sure if I am missing something.

Do you have experience with those two commands?

Thanks

Last edited by csj79; 11-30-2022 at 01:57 PM.
 
Old 11-30-2022, 01:57 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,782
Blog Entries: 3

Rep: Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514
As per the manual page the -a option is a superset of the -p option.

The -p is the same as --preserve=mode,ownership,timestamps

The -a is the same as --preserve=all --no-dereference --recursive
 
1 members found this post helpful.
Old 11-30-2022, 02:00 PM   #3
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that works well on freest; has been KDE, CLI, Novena but open... http://goo.gl/NqgqJx &c ;-)
Posts: 4,640
Blog Entries: 2

Rep: Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500Reputation: 1500
Did you give the archive a name
Code:
$ cp -a whatever/ name
$ cp --archive whatever/ name
man?
 
Old 11-30-2022, 04:45 PM   #4
csj79
LQ Newbie
 
Registered: Aug 2022
Posts: 17

Original Poster
Rep: Reputation: 0
I ran cp -a Folder1/* Folder2/ and cp -p Folder1/* Folder2/
It seems like in both cases, all files were copied from Folder1 to Folder2 while preserving their original permissions , owners and groups and timestamps. I was not able to see the difference with both commands
 
Old 11-30-2022, 05:51 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,132

Rep: Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340
As posted -a = --preserve=all --no-dereference --recursive
--perserve=all -> all = mode,ownership,timestamps and if possible additional attributes: context, links, xattr

-p == --preserve=mode,ownership,timestamps

With respect to the output of the ls command there should be no difference between attributes of the two files. If you want to see the extended attributes for the files you can use the getxattr command.

With -a you also have the additional options
-d same as --no-dereference --preserve=links

Which means copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. If the folders do not contain links then you are not going to see a difference.

Last edited by michaelk; 11-30-2022 at 05:58 PM.
 
1 members found this post helpful.
Old 11-30-2022, 10:04 PM   #6
csj79
LQ Newbie
 
Registered: Aug 2022
Posts: 17

Original Poster
Rep: Reputation: 0
thank you for the very detailed response michaelk. I appreciate it. I am still new to Linux and and learning everyday.

I now see that the cp -a is a better option as it preserves all attributes of the original file.

Thanks again for your help
 
Old 11-30-2022, 10:10 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,782
Blog Entries: 3

Rep: Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514
Quote:
Originally Posted by csj79 View Post
I now see that the cp -a is a better option as it preserves all attributes of the original file.
However, it does that at the cost of adding a --recursive option. You might not always want a recursive copy. If you want to preserve all the attributes of the original file, then you can use either the shortcut --perserve=all or else the full list --preserve=mode,ownership,timestamps,context,links,xattr plus --no-dereference
 
  


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
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
xfs and disk space and tar and squid and rc.local!!! Paul Reed Linux - Software 7 06-23-2006 02:28 PM
is it legitimate and allowed and can be done to make another user account set uid and gid to null 0 to make another root account with different name and possibly not damage the debian system creating and using that new account BenJoBoy Linux - Newbie 12 01-29-2006 10:02 AM
Asus P4C800-E Deluxe and Mandrake and Intel ICH5R and RAID 0 and 74 GB Raptors SeattleGoozyGuy Linux - Software 2 09-13-2004 02:05 PM
Asus P4C800-E Deluxe and Mandrake and Intel ICH5R and RAID 0 and 74 GB Raptors SeattleGoozyGuy Linux - Hardware 1 05-31-2004 06:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration