Page 1 of 1

unable to understand "cp"

Posted: Sun Aug 19, 2012 11:56 am
by guachinver
I apologize for asking this simple question.
I wanted to copy an entire directory and its subdirectories and it still fails.

cp /var/www /media/harddisk did not copy all subdirectories
cp -Rv /var/www /media/ harddisk did not copy all subdirectories!
cp -rv /var/www /media/ harddisk did not copy all subdirectories!
cp -av /var/www /media/ harddisk Copy all files and subdirectories but does not respect! original owner or group

I guess it's a problem depending on permissions, I used root (sudo) and neither has performed well.
A page where I can read and understand this behavior "cp"?
The verbose parameter is not sufficient for read what files or directorys are not copied?

The copy was to transfer a web site to a new directory, some pages had links that did not include default suffix. "Html", probably because the owners have changed it after you copy the links do not work.
The server is a working Apache2 on Debian 6.0 (Raspberrypi) where I can read to try to understand this strange behavior?

The target hard disk file system is NTFS USB, I installed ntfs-3g, perhaps NTFS don´t have owner or group?.

Thanks in advance
Andres

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 1:35 pm
by joan
For documentation on a command try man, e.g.

man cp

You probably want

sudo cp -a /var/www /media/harddisk

Mind you I'm not sure if NTFS (because of its proprietary nature) is safely writable from Linux/Gnu.

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 1:42 pm
by nroff-man
Hi.

You may find it easier to format your drive using ext2 then
if you need to access the drive from elsewhere use `Ext2Fsd'.

Bye

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 1:59 pm
by jojopi
guachinver wrote:The verbose parameter is not sufficient for read what files or directorys are not copied?
You are actually better not to use the verbose option. One of the nice features of unix commands is that they normally produce output only when something goes wrong. If any subdirectories can not be copied, the program will tell you which and why, but these errors will be much easier to see if they are not mixed in with noise about the files copied successfully.

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 2:09 pm
by Joe Schmoe
jojopi wrote:
guachinver wrote:The verbose parameter is not sufficient for read what files or directorys are not copied?
You are actually better not to use the verbose option. One of the nice features of unix commands is that they normally produce output only when something goes wrong. If any subdirectories can not be copied, the program will tell you which and why, but these errors will be much easier to see if they are not mixed in with noise about the files copied successfully.
That's one theory.

A better theory is to realize that visual feedback is good, since commands do hang, and you never really know if a long-running command is doing stuff or not. So, a good way to cater to both needs is to separate the stdout and stderr streams, so that you can view them separately and see a steady stream of successes (visual feedback) in one window and the occasional (we hope never!) errors in another.

One way to do this on Linux is like this (assume you are logged in on tty1):

cp -v whatever wherever > /dev/tty5

Now, you'll get your errors on your main screen and your steady stream of visual feedback on tty5 (which, of course, as we all know, you reach by typing Alt/F5)

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 4:36 pm
by guachinver
joan wrote:
You probably want

sudo cp -a /var/www /media/harddisk
I had tried to express that I have also tried.

sudo cp -a /var/www /media/harddisk
sudo cp -av /var/www /media/harddisk

With the result of copying files and subdirectories but without preserving owner and group. Contrary to what man says about the -a parameter!
Sorry for my bad English.

Interestingly, the issue raised by the "verbose" parameter, I usually do not use it but in this case when the cp command has not done what I expected I used -v to perform a kind of "debug" to see what happened.
Interesting input from Joe Schmoe, I like the idea of ​​dual console.
nroff-man wrote:
You may find it easier to format your drive using ext2 then
if you need to access the drive from elsewhere use `Ext2Fsd'.
Because I use a mixed OS environment with several computers I prefer mantain the NTFS file system in this disk, if is possible of course!.

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 4:41 pm
by joan
The permissions/owners will not be preserved when copied to an NTFS system. NTFS is Windows and handles permissions/owners in a different way.

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 5:31 pm
by guachinver
joan wrote:
The permissions/owners will not be preserved when copied to an NTFS system
Thanks for the answer, because when this happens to someone new, like me, you just want to leave linux on the initiation phase.
Since operate with this file system, NTFS, is unsafe and risky will set it up another file system. I would appreciate any suggestions besides "ext2".

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 5:53 pm
by Joe Schmoe
Actually, NTFS-3g (FUSE) is just fine and safe. I actually think there's a lot to be said for keeping external media formatted NTFS - for all the usual reasons. But, alas, as others have noted, you won't get Unix style permissions, ownerships, etc. If you absolutely need those, you will need to format it to something Unix-y (presumably, EXT4)

Or, you could go with a loop filesystem hosted on the NTFS drive - format the loop filesystem to EXT4. Then you get the best of both worlds - at a certain price in performance, of course...

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 6:53 pm
by r4049zt
Not sure about this, but if you try again what you had tried, with a * at the end, does it copy?
* is supposed to mean "anything"

Re: unable to understand "cp"

Posted: Sun Aug 19, 2012 8:41 pm
by guachinver
Joe Schmoe wrote:Actually, NTFS-3g (FUSE) is just fine and safe.
For me it's risky than after executing the command sudo cp -r not all files and directories are copied.
It seems unsafe to operate with NTFS file system in the "raspi" because I do not obtain any error when doing a sudo cp -r, even without copying all subdirectories.
I lack all knowledge to evaluate ntfs-3g except ease of installation and usability.
I'll try to use EXT4