Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ditto on OS X to work like cp -a on Linux

Tags:

macos

I'm a Linux guy and I'm used to copying directory trees with cp -a. OS X doesn't have -a option on cp... but it does have the ditto command. I'm reading the man on ditto now, but is there anything I should specifically be looking out for?

like image 482
Trenton Avatar asked Oct 01 '08 23:10

Trenton


2 Answers

According to the cp man page cp -a is the same as cp -dpR which is

-p = preserve mode,ownership,timestamps
-R = recursive
-d = no dereference and preserve links

The OS X equivalent would be

cp -pPR

-p = preserve
-R = recursive
-P = no symbolic links are followed -- can be added but this is the default behavior

The only thing missing is -d which I think is the default behavior but I'm not positive.

I've never messed with ditto

Edit -- @SoloBold

-L follows symbolic links. -p does NOT follow symbolic links. OS X (10.4 at least) has no -d option.

that is a huge difference.

like image 150
Simurr Avatar answered Nov 13 '22 09:11

Simurr


Personally I use rsync -a (or whatever rsync params are called for). My two reasons are: I already know how to do this, and I need my scripts to be portable across Linux/BSD/Solaris. There are also some filesystems where rsync is more efficient than cp.

Sorry that's not a direct answer, I have used ditto on BSDs but don't have any gotchas for you that aren't in the man page.

like image 27
joelhardi Avatar answered Nov 13 '22 10:11

joelhardi