I am having an issue where I have Parent folder that has full permissions.. I can create a new folder and that folder also has full permissions. However when I copy a folder over to this parent Directory and try to create a new directory to this copied directory. it loses all permissions.. is there a way to retain permissions to the copied folders..
Yes. When copying using
-p option preserves permissions.
-p same as --preserve=mode,ownership,timestamps --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all
1I normally use
cp -ato preserve modtime as well. (And to enable recursive copying, in the rare case I'm using cp for that instead of rsync to preserve hardlinks.) Mar 15, 2021 at 12:23
@PeterCordes Note that
-palready preserves timestamps and
-ais a non-POSIX extension. Mar 15, 2021 at 14:19
In addition to steve's answer, you can use
rsync -avhH /path/to/source /path/to/destination
a switch preserves permissions, modify times, ownership, and also makes it recursive and copies symlinks.
v makes it verbose and
H respectively make the output human readable and copies hardlinks.
a is important as that does what you want.
I like a tar pipe for retaining user/group ownership and permissions, and for tar's flexibility for defining which files to copy
tar cf - -C sourcedir -T filelist | tar xvf - -C targetdir