rsync --no-perms は依然として権限を保持し、umask を無視します。

rsync --no-perms は依然として権限を保持し、umask を無視します。

使ってみようhttps://unix.stackexchange.com/a/315667/21372rsyncを使用してcpのバグの回避策がありますが、正しく動作しません。rsyncデフォルトでは、同様のアプローチを使用してファイルまたはディレクトリを繰り返しコピーする必要がありますが、一般的なumask条件を使用してファイルとディレクトリを作成する必要がありますrsync -a。ただし、単一のファイルに対してこれを試してみると、そのオプションを指定しても、--no-permsターゲットファイルに対する権限がまだ維持されていることがわかります。

bash-4.1$ cd /tmp
bash-4.1$ touch afile
bash-4.1$ chmod a-w afile
bash-4.1$ ls -ld afile
-r--r--r-- 1 theuser thegroup 0 Jul 24 16:50 afile
bash-4.1$ rsync --copy-links --recursive --times --group --no-perms afile afile2
bash-4.1$ ls -ld afile*
-r--r--r-- 1 theuser thegroup 0 Jul 24 16:50 afile
-r--r--r-- 1 theuser thegroup 0 Jul 24 16:50 afile2
bash-4.1$ 

afile2私が望むのは、通常の作成と同じ権限を持つことです。afile3

bash-4.1$ touch afile3
bash-4.1$ ls -ld afile3
-rw-rw-r-- 1 theuser thegroup 0 Jul 24 16:51 afile3

以下のように "harsh"を使用してコマンドを見つけることができます。https://unix.stackexchange.com/a/315667/21372--no-permsしかし、私はrsyncオプションが実行する必要があると思うタスクを実行するために後続のfindコマンドのオーバーヘッドを必要としません。

これはユーザースペースで機能する必要があります(ルートは必要ありません)。

これはrsyncのバグですか、それともユーザーエラーですか?

関連するオペレーティングシステムとrsyncのバージョンは次のとおりです。

bash-4.1$ lsb_release -r -i
Distributor ID: RedHatEnterpriseWorkstation
Release:    6.8
bash-4.1$ rsync --version
rsync  version 3.0.6  protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
bash-4.1$ 

ベストアンサー1

rsyncのマニュアルページから:

新しいファイルにターゲットのデフォルト権限を付与するには(既存のファイルは変更せずに)、--permsオプションがオフになっていることを確認し、--chmod = ugo = rwXを使用します(これにより、すべてのマスク解除ビットが有効になります)。

だから...

rsync --copy-links --recursive --times --group --no-perms --chmod=ugo=rwX afile afile2

...表示されたサンプルファイルでこの問題を解決する必要があります。

ソースファイルに777と同じ権限がある場合...

rsync --copy-links --recursive --times --group --no-perms --chmod=ugo=rw,-X afile afile2

...実行可能フラグを削除します。

おすすめ記事