Rodolfo Medina wrote: >> When I copy a file into the present directory, with: >> >> $ cp /path/to/file . >> >> , if the file already exists it is overwritten, i.e. the `old one' >> is removed and the `new one' takes its place. >> Instead, with directories it is not the same: >> when I do: >> >> $ cp -vr /path/to/dir . >> >> , if the directory already exists it is not removed, but the new one >> just adds files to the old one. >> >> Would it be possible, and how?, to have with directory overwriting >> the same behaviour we have with file overwriting?
Roberto C. Sanchez wrote: > You could probably write a script to "replace" the current cp command: > > #!/bin/bash > > if [ -d $3 ] ; then > /bin/rm -rf $3 > fi > > /bin/cp $1 $2 $3 > > Of course, you will need to handle the command line parameters more > intelligently (this script only handle one clump of switches). Digby Tarvin <[EMAIL PROTECTED]> writes: > [...] > > For example, a script to do this might be something like > #!/bin/sh > if [ "$#" != "2" ] ;then > echo "Usage: cpdir <src> <tgt>" > exit 1 > fi > DIRNAME=`basename $1` > if [ -r $2/$DIRNAME ] ;then > rm -r $2/$DIRNAME > fi > cp -rv $1 $2 > > With this, the args from your original example: > $ cpdir /path/to/dir . > > would result in a directory called 'dir' in '.' containing the > same information as the original - if that is what you wanted.. Thanks for your replies. I'll be trying your suggestions. Cheers, Rodolfo -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]