What does the -rd option mean in the cp command?

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"?


Solution 1:

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’.

Solution 2:

In many command line utilities, single-letter options can be written together. In your case, the longer form would be

cp -r -d  *  /folder_1/

which can be shortened to

cp -rd  *  /folder_1/

The other version

cp -dr  *  /folder_1/

is the same as

cp -d -r  *  /folder_1/