Ubuntu – What does the -rd option mean in the cp command

command linecp

I have found a reference using the following command

cp -rd  *  /folder_1/

and another one as

cp -dr * /folder_2/

Can you please advise what are these options "rd" or "dr"?

Best Answer

The order does not matter - you can give the options in any order

This combination will copy directories recursively (including all the contents) and copy symlinks as symlinks instead of copying the files they point to.

-d is only needed when using -r : it is used to override the default behaviour, which is not to follow symlinks when copying recursively

from info cp

‘-r’ ‘--recursive’ Copy directories recursively. By default, do not follow symbolic links in the source unless used together with the ‘--link’ (‘-l’) option; see the ‘--archive’ (‘-a’), ‘-d’, ‘--dereference’ (‘-L’), ‘--no-dereference’ (‘-P’), and ‘-H’ options.

‘-d’ 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. Equivalent to ‘--no-dereference --preserve=links’.