[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Directory overwriting



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?


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).

-Roberto

--
Roberto C. Sanchez
http://familiasanchez.net/~roberto



Reply to: