advertisement

Article:
  Learning the Mac OS X Terminal, Part 2
Subject:   quibble re 'cp -r A B'
Date:   2002-01-29 07:05:36
From:   hayne
In the article, the command:
cp -r Library/Mail/ Documents/Mail
is used to make a backup copy of the Mail directory. The author comments:
"The target pathname, Documents/Mail, doesn't specify the directory in which you would like Library/Mail/ to go, but the desired new relative pathname of the copied directory."


This is true only if the target directory (Documents/Mail) doesn't exist. If it did exist, for example if you were doing this backup copy operation a second time, then the target is in fact the place to which the copy will be put.


I.e. if A is a directory and there is no directory B, then cp -r A B makes a new copy of directory A and names it B. But if the directory B already exists, then cp -r A B makes a new copy of directory A and names the copy B/A (The copy is named A but is in the existing directory B )


So, starting from a situation where there is no directory named Documents/Mail, the result of doing the copy operation twice:
cp -r Library/Mail/ Documents/Mail
cp -r Library/Mail/ Documents/Mail
would be a directory Documents/Mail which would have a copy of Library/Mail, but which would also have a subdirectory Documents/Mail/Mail with a second copy.


A second quibbble is with the use of the "-r" option. It would be better to use the "-R" option (capital R). The man page for 'cp' says:
"Historic versions of the cp utility had a -r option. This implementation supports that option, however, its use is strongly discouraged, as it does not correctly copy special files, symbolic links or fifo's."




1 to 1 of 1
  1. Chris Stone photo quibble re 'cp -r A B'
    2002-01-29 09:33:46  Chris Stone | O'Reilly AuthorO'Reilly Blogger [View]

1 to 1 of 1