cp -rとcp -R(コピーコマンド)の違い

cp -rとcp -R(コピーコマンド)の違い

cp -rファイルを再帰的にコピーし、cp -Rディレクトリを再帰的にコピーすることを意味します。しかし、確認してみると、両方ともファイルとディレクトリをコピーしているようです。では、実際の違いは何ですか?

ベストアンサー1

-Rposixは明確に定義されていますが、移植性-rはありません!

Linuxでは、実装はGNUとBusyBoxで同じcpです。-r-R

一方、できるだけPOSIXcpアクションのマニュアルページ-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.

おすすめ記事