Sample Header Ad - 728x90

To copy using cp non-recursively if the '-a' option is already used

0 votes
0 answers
68 views
BSD cp:
-a    Archive mode.  Same as -RpP options. Preserves structure and
           attributes of files but not directory structure.

     -P    No symbolic links are followed.  This is the default if the -R
           option is specified.

     -R    If source_file designates a directory, cp copies the directory and
           the entire subtree connected at that point.  If the source_file
           ends in a /, the contents of the directory are copied rather than
           the directory itself.  This option also causes symbolic links to be
           copied, rather than indirected through, and for cp to create
           special files rather than copying them as normal files.  Created
           directories have the same mode as the corresponding source
           directory, unmodified by the process' umask.

     -p    Cause cp to preserve the following attributes of each source file
           in the copy: modification time, access time, file flags, file mode,
           user ID, and group ID, as allowed by permissions.  Access Control
           Lists (ACLs) and Extended Attributes (EAs), including resource
           forks, will also be preserved.

           If the user ID and group ID cannot be preserved, no error message
           is displayed and the exit value is not altered.

           If the source file has its set-user-ID bit on and the user ID
           cannot be preserved, the set-user-ID bit is not preserved in the
           copy's permissions.  If the source file has its set-group-ID bit on
           and the group ID cannot be preserved, the set-group-ID bit is not
           preserved in the copy's permissions.  If the source file has both
           its set-user-ID and set-group-ID bits on, and either the user ID or
           group ID cannot be preserved, neither the set-user-ID nor set-
           group-ID bits are preserved in the copy's permissions.
GNU cp:
-a, --archive
              same as -dR --preserve=all

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

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

       -R, -r, --recursive
              copy directories recursively

       --preserve[=ATTR_LIST]
              preserve the specified attributes
- Is there a difference between BSD and GNU cp -a in practice? - Is there a way to cp non-recursively if the -a option is already used, that is, to overwrite its -R part?
Asked by jsx97 (1347 rep)
Jul 31, 2024, 12:58 PM