回答:
一方で-R、明確に定義されたPOSIXされ、-r移植性がありません!
Linuxでは、GNUとBusyBoxの実装でcp、-rおよび-Rは同等です。
反対に、のPOSIXマニュアルページを読むとわかるようにcp、-r動作は実装定義です。
* If neither the -R nor -r options were specified, cp shall take actions based on the type and contents of the file referenced by the symbolic link, and not by the symbolic link itself. * If the -R option was specified: * If none of the options -H, -L, nor -P were specified, it is unspecified which of -H, -L, or -P will be used as a default. * If the -H option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand. * If the -L option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand or any symbolic links encoun- tered during traversal of a file hierarchy. * If the -P option was specified, cp shall copy any symbolic link specified as a source_file operand and any symbolic links encoun- tered during traversal of a file hierarchy, and shall not follow any symbolic links. * If the -r option was specified, the behavior is implementation- defined.
-rシンボリックリンクが指す実際のファイル-Rをコピーする一方で、ほとんどの場合に意図されているシンボリックリンクをコピーすることです。
違いは、一方が小文字の「R」を使用し、もう一方が大文字の「R」を使用することです。それを超えて、違いはありません。--recursive長いオプションを使用する場合も同じです。
cpは、実際には違いがあります。Random832の回答を参照してください。@Ignacioこの回答には、「もしあなたcpが最新のGNU実装なら」などの修飾子を含めるべきです。
-R、そして実際、今述べたシステムのmanページのいくつかはそれも推奨しています。
小文字-rは4.1BSDで導入された古いオプションで、すべての非ディレクトリをファイルとして単純にコピーします。つまり、デバイスまたはFIFOに遭遇した場合、デバイスまたはFIFOを開き、コンテンツを読み取り、そのコンテンツを使用して宛先にファイルを作成します。
大文字-Rは標準化されたオプションで(4.4BSDでBSDに導入されましたが、以前のバージョンではの同義語として使用されていました-r)、デバイス、FIFO、またはその他の特殊ファイルに遭遇すると、宛先に同等の特殊ファイルを作成します。
多くの実装はまだこの区別を維持していますが、一部(Linuxに典型的なGNUバージョンを含む)は同義語として-Rセマンティクスのみを提供し-rます。
OS XおよびFreeBSDの古いバージョンはcoreutilsの-rよう-R -L --copy-contentsであるか、シンボリックリンクをたどり、特別なファイルとFIFOの内容を読み取ります。
mkdir a;touch b;ln -s $PWD/b a;cp -r a cOS Xでシンボリックリンクをターゲットファイルに置き換え、mkdir a;mkfifo a/b;cp -r a cFIFOの読み取りをブロックし、ゼロでmkdir a;ln -s /dev/zero a;cp -r a b埋め始めb/zeroます。
cpOS Xおよび古いバージョンのFreeBSD のmanページから:
Historic versions of the cp utility had a -r option. This implementation
supports that option; however, its use is strongly discouraged, as it
does not correctly copy special files, symbolic links, or fifo's.
FreeBSDの新しいバージョンで-rは、-RL次と同等です:
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 imple-
mentations of -r differ as they copy special files as normal files while
recreating a hierarchy.
http://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html:
--copy-contents再帰的にコピーする場合は、特殊ファイル(FIFOやデバイスファイルなど)の内容を通常のファイルであるかのようにコピーします。これは、各ソースファイルのデータを読み取って宛先に書き込むことを意味します。通常、このオプションを使用するのは間違いです。通常、FIFOなどの特殊ファイルや、通常
/devディレクトリにあるファイルに望ましくない影響があるためです。ほとんどの場合、cp -R --copy-contentsFIFOやなどの特殊ファイルから読み取ろうとして無期限にハング/dev/consoleし、コピーに使用すると宛先ディスクがいっぱいになります/dev/zero。このオプションは、再帰的にコピーしない限り効果がなく、シンボリックリンクのコピーには影響しません。
違いの1つは、-rが隠しディレクトリをコピーしないのに対し、-rは隠しディレクトリをコピーしないことです。
ターゲットディレクトリの.gitディレクトリをテストし、上記の結論に達しました。現在、centOSを使用しています。
私は間違っているかもしれませんが、議論の余地はあります。
-rそして、-Rの両方が隠しディレクトリにコピー