I had copied a directory contain C language source code files and some shell scripts from my Ubuntu 12.10 64 bit laptop to a portable hard disk some time back. I had copied it under root login. Now, today when I copied it back from the portable disk to the same laptop under root login, I observed that the file permissions had changed from the original 755 to 400 which caused some scripts to fail. How should I copy to the hard disk so that the directory and its content retain the permissions?
2 Answers
Your external drive is using either FAT32 or NTFS, which do not support permissions. You either need to switch to a unix compatible format on the external drive, or you can use tar
( or the gui archive utility ) to preserve the correct permissions in the archive while it is stored on such a disk.

- 37,551
Maybe this is not the case, but it may depend on the filesystem: e.g. FAT32 formatted drives do not support file permissions. have a look at this question: How do I change file permissions on a FAT32 drive?.
Other than that, I would have a look at rsync manual.
rsync -aPv what where
-a is for archive mode, which is often what you want: permissions/owner/group preserved, recursive behavior, and quite a lot of other staff. (-P and -v increase the verbosity and gives you a better look)
specifically, the -p flag will keep your permissions.

- 196
-
is it -p or -P ? – Jay Jan 09 '14 at 14:41
-
-p is for permissions only. you may want to use -a instead. -P stands for --progressive --partial, which means keep the partial transferred files and gives you something to look at while the file transfer is going on. so a totally unrelated option, but useful. – MarcDuQuesne Jan 09 '14 at 14:43