-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
With cp, the mode on a directory is not being copied unless explicitly cited in --preserve, which is a change in behavior. (I'm reporting this due to: "Differences with GNU are treated as bugs", from the project goals.)
This is related to issue #5125, but my experience is that -a copies the mode.
First, baseline behavior. Note the 755 mode of testdir is copied.
$ ls -ltR /tmp/cp_source
/tmp/cp_source:
total 4
drwxr-xr-x 2 scott scott 4096 Mar 9 22:48 testdir
-rwxr-xr-x 1 scott scott 0 Mar 9 22:47 testfileparent
/tmp/cp_source/testdir:
total 0
-rwxr-xr-x 1 scott scott 0 Mar 9 22:48 testfilechild
$ cp -RP --preserve=ownership,timestamps /tmp/cp_source /tmp/cp_target
$ ls -ltR /tmp/cp_target
/tmp/cp_target:
total 4
drwxr-xr-x 2 scott scott 4096 Mar 9 22:48 testdir
-rwxr-xr-x 1 scott scott 0 Mar 9 22:47 testfileparent
/tmp/cp_target/testdir:
total 0
-rwxr-xr-x 1 scott scott 0 Mar 9 22:48 testfilechild
$ umask
0002
$ which cp
/usr/bin/cp
$ cp --version
cp (GNU coreutils) 9.4
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Torbjörn Granlund, David MacKenzie, and Jim Meyering.
$ grep PRETTY /etc/os-release
PRETTY_NAME="Pop!_OS 24.04 LTS"
$
Next, the differing be behavior. Note the 755 mode of testdir is NOT copied, until "mode" is added to the --preserve list.
$ ls -ltR /tmp/cp_source
/tmp/cp_source:
total 0
drwxr-xr-x 2 scott scott 60 Mar 9 22:48 testdir/
-rwxr-xr-x 1 scott scott 0 Mar 9 22:47 testfileparent
/tmp/cp_source/testdir:
total 0
-rwxr-xr-x 1 scott scott 0 Mar 9 22:48 testfilechild
$ cp -RP --preserve=ownership,timestamps /tmp/cp_source /tmp/cp_target
$ ls -ltR /tmp/cp_target
/tmp/cp_target:
total 0
drwx------ 2 scott scott 60 Mar 9 22:48 testdir/
-rwxr-xr-x 1 scott scott 0 Mar 9 22:47 testfileparent
/tmp/cp_target/testdir:
total 0
-rwxr-xr-x 1 scott scott 0 Mar 9 22:48 testfilechild
$ # But explicitly specifying mode does work:
$ rm -rf /tmp/cp_target
$ cp -RP --preserve=mode,ownership,timestamps /tmp/cp_source /tmp/cp_target
$ ls -ltR /tmp/cp_target
/tmp/cp_target:
total 0
drwxr-xr-x 2 scott scott 60 Mar 9 22:48 testdir/
-rwxr-xr-x 1 scott scott 0 Mar 9 22:47 testfileparent
/tmp/cp_target/testdir:
total 0
-rwxr-xr-x 1 scott scott 0 Mar 9 22:48 testfilechild
$ umask
0002
$ which cp
/usr/bin/cp
$ cp --version
cp (uutils coreutils) 0.6.0
$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="AerynOS 2026.02"
$
Sorry I can't submit a patch... I'm not a ruster. :-\ Much appreciation for all you do, folks. :-)
Reactions are currently unavailable