-1

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?

  • It would be helpful if you included the command that you used to do this. – Ryan Apr 9 '16 at 5:55
1

I often use rsync for saving file permissions while copying.

rsync [OPTION...] SRC... [DEST]

Using the -p option will preserve permissions:

-p, --perms
     preserve permissions

and using -a (archive) will add a few more options:

-a, --archive
     archive mode; equals -rlptgoD (no -H,-A,-X)

See man rsync for usage details and more options.

0

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 (cp, rsync, etc) have options to preserve the original permissions - so the copied files don't get created with whatever perms are specified by your umask.

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.

0

Since your question has the /cp tag, I'll assume you used cp. From the coreutils documentation for cp:

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

The -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 -l, -a, -L, -P, or -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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.