# Is it safe to use 'cp -r' in FreeBSD?



## chuan huang (Nov 12, 2016)

Hello,

The command 'cp -r' is used to copy files recursively from one position to another position in Linux. I found this command also works well in FreeBSD. However the '-r' option is not mentioned in the man page of 'cp', although there is an equivalent option '-R'. So, I was wondering whether is it safe to use 'cp -r' in FreeBSD.

Additionly, to copy an entire directory, we need to make sure the endmost '/' of a directory is omitted in 'cp -R'. Is there any way to work around this? (That means keep the '/' and copy the whole directory)

Thanks.


----------



## topcat (Nov 12, 2016)

As regards the use of the -r flag, here's what the man page of cp() has to say:



> Historic versions of the cp utility had a -r option. This implementation supports that option, however, its behavior is different from historical FreeBSD behavior. Use of this option is strongly discouraged as the behavior is implementation-dependent. In FreeBSD, -r is a synonym for -RL and works the same unless modified by other flags. Historical implementations of -r differ as they copy special files as normal files while recreating a hierarchy.



-L follows symlinks, btw. HTH.


----------



## ANOKNUSA (Nov 13, 2016)

At the risk of presuming too much: just rewrite your scripts to conform completely to FreeBSD conventions. If they're vital to your day-to-day work then the small cost of a few keystrokes now could save you the cost of a whole day fixing a disaster.


----------

