3

サーバー上のある場所から別の場所にディレクトリ構造全体をコピーしました。

cp -r /home/abc/public_html/* /home/xyz/public_html/

それはうまくいきました。rootディレクトリとファイルが現在所有されており、グループも所有されていることを除いてroot

ownershipこのコピー アクションを実行し、dirs & files 、groups、およびpermission設定を保持するにはどうすればよいですか?

これが私のman cp

NAME
       cp - copy files and directories

SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

       Mandatory arguments to long options are mandatory for short options too.

       -a, --archive
              same as -dR --preserve=all

       --backup[=CONTROL]
              make a backup of each existing destination file

       -b     like --backup but does not accept an argument

       --copy-contents
              copy contents of special files when recursive

       -d     same as --no-dereference --preserve=links

       -f, --force
              if an existing destination file cannot be opened, remove it and try again (redundant if the -n option is used)

       -i, --interactive
              prompt before overwrite (overrides a previous -n option)

       -H     follow command-line symbolic links in SOURCE

       -l, --link
              link files instead of copying

       -L, --dereference
              always follow symbolic links in SOURCE

       -n, --no-clobber
              do not overwrite an existing file (overrides a previous -i option)

       -P, --no-dereference
              never follow symbolic links in SOURCE

       -p     same as --preserve=mode,ownership,timestamps

       --preserve[=ATTR_LIST]
4

5 に答える 5

2

cp -a権限とユーザー/グループをコピーするために使用します。

マニュアルページでは次のように説明されています。

-a, --archive
    same as -dR --preserve=all
...
-d     same as --no-dereference --preserve=links
...
-R, -r, --recursive
   copy directories recursively
...
--preserve[=ATTR_LIST]
   preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes:
   context, links, xattr, all
于 2014-10-01T12:14:44.380 に答える
2

「cp -a」という答えは、一部の UNIX 関連のオペレーティング システム (たとえば、coreutils の「cp」を使用する Linux) では正しいですが、すべてではありません。

「cp -rp」は他のものに適しています。

特定のオペレーティング システムの「cp」については、マニュアル ページを参照してください。または、使用しているものをお知らせください。

于 2014-10-01T12:17:25.047 に答える
1

からman cp

-p    Cause cp to preserve the following attributes of each source file
       in the copy: modification time, access time, file flags, file mode,
       ACL, user ID, and group ID, as allowed by permissions.

だから cp -pr

于 2014-10-01T12:14:51.247 に答える
1

man cp言います:

-p     same as --preserve=mode,ownership,timestamps
于 2014-10-01T12:14:54.957 に答える
0

余談ですが、次のことは避けてください。

cp -r src/* dest

隠しファイルをコピーしないため

Linux では次のようにします。

cp -rT src dest

および BSD では:

cp -R src/ dest
于 2020-08-05T10:47:51.490 に答える