Re: Help with command - cp
* Mr Smiley wrote on 2014-01-26 at 20:56 (+0000):
> > cp -Rp /path/to/sourcedir/A/* /path/to/destinationdir/B
>
> If you don't put a / after B it will copy all files to a file
> called B
No, obviously not.
$ mkdir src
$ echo foo > src/file1
$ echo bar > src/file2
$ echo baz > src/.hidden1
$ [ -e ./target ] || echo "./target not found!"
./target not found!
$ cp -Rp ./src/* ./target
cp: target `./target' is not a directory
$ cp -Rp ./src/* ./target/
cp: target `./target/' is not a directory
$ [ -e ./target ] || echo "./target not found!"
./target not found!
> So your above
> cp -Rp /path/to/sourcedir/A/* /path/to/destinationdir/B
> Should be
> cp -Rp /path/to/sourcedir/A/* /path/to/destinationdir/B/
If the target directory *exists* the trailing slash will *not* be
necessary:
$ mkdir target1 target2
$ cp -Rp ./src/* ./target1
$ cp -Rp ./src/* ./target2/
Both directories are identical. There will be no *file* B!
> Also when using rsync, i use the following
>
> rsync -vrthiP --progress --stats source/ destination/
>
> This also checks for and only updates changed files on any
> subsequent rsync from A to B
>
> Don't forget the / at the end, even rsync will copy everything to a
> file rather than the wanted directory if you miss of the /
That's not correct. In contrast to the slash trailing the
*source*, the final slash trailing the *target* is completely
irrelevant. See my other mail.
Regards,
Mathias
Reply to: