すべてのファイル/ディレクトリ属性を別のファイル/ディレクトリに複製/コピーする方法は?

すべてのファイル/ディレクトリ属性を別のファイル/ディレクトリに複製/コピーする方法は?

あるディレクトリの属性(所有権、グループ、ACL、拡張属性など)を別のディレクトリにコピーしたいのですが、ディレクトリの内容自体はコピーしたくありません。

これはうまくいきません:

cp -v --attributes-only A B
cp: omitting directory `A'           

メモ:必ずしもそうではありませんcp

ベストアンサー1

コマンドラインで数多くの試行錯誤の末に答えを見つけたようです。しかし、これは適切な答えではありませんcp

rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir

これは次のことを行います。

-p, --perms                 preserve permissions
-t, --times                 preserve modification times
-o, --owner                 preserve owner (super-user only)
-g, --group                 preserve group
-d, --dirs                  transfer directories without recursing
-A, --acls                  preserve ACLs (implies --perms)
-X, --xattrs                preserve extended attributes
    --no-recursive          disables recursion

参考までに

    --no-OPTION             turn off an implied OPTION (e.g. --no-D)
-r, --recursive             recurse into directories

おすすめ記事