I have two directory in two different path there are some common subdirectories and files between them I want to copy the content of first directory to the second one meanwhile I need the same permission but after copying the file the permission changed now the permission of my files are -rwxr-xr-x it should be change to lrwxrwxrwx. How can I change the permission to this format?
closed as unclear what you're asking by G-Man, Wildcard, user79743, Jakuje, Anthon Apr 9 '16 at 10:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I often use
rsync for saving file permissions while copying.
rsync [OPTION...] SRC... [DEST]
-p option will preserve permissions:
-a (archive) will add a few more options:
archive mode; equals -rlptgoD (no -H,-A,-X)
man rsync for usage details and more options.
If the original file permissions started with
l rather than
-, then they weren't files, they were symbolic links to other files/directories.
Whatever command you used to copy them copied the actual files they referred to, not the symbolic links. Only symlinks have an
l at the start of the permissions display, normal files start with
-. in other words, there is no problem.
If you want to copy the symlinks (rather than the files they point to), read the man page for whatever tool you used to copy the files (
cp, perhaps? you didn't specify) and see if it has an option to NOT follow symlinks.
Similarly, most copying tools (
rsync, etc) have options to preserve the original permissions - so the copied files don't get created with whatever perms are specified by your
Note that only root can fully preserve ownership, group, and all perms of copied files because a normal user can't create files owned by someone else or with a group that they are not a member of.
When copying from a symbolic link, cp normally follows the link only when not copying recursively or when --link (-l) is used. This default can be overridden with the --archive (-a), -d, --dereference (-L), --no-dereference (-P), and -H options. If more than one of these options is specified, the last one silently overrides the others.
To copy the symbolic links instead of the linked files, you can use the
-d flag for
cp like this:
cp -d SOURCE DEST
-d flag will force
cp to copy symbolic links as symbolic links. From the coreutils docs:
Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies. Equivalent to --no-dereference --preserve=links.
If you used other flags in this copy process, you should be able to simply add
-d to your flags, unless one of those other flags was
-H (see above note about using more than one option). In that case, you would have to be careful with the order of the flags, or remove the unnecessary flags.