Edit: Found a duplicate with solution: rsync -a --delete https://stackoverflow.com/questions/23698183/how-to-force-cp-to-overwrite-directory-instead-of-creating-another-one-inside
new script that works:
#!/bin/bash
numCopy=$1
shift
cmdline="${@}"
echo "prepare folders"
for ((i=1;i<=$numCopy;i++));
do
(rsync -a --delete $cmdline/ $cmdline$i/; ) &
(echo "preparing folder clone: $i") &
done
wait
For multithreaded folder copying,
#!/bin/bash
numCopy=$1
shift
cmdline="${@}"
echo "prepare folders"
for ((i=1;i<=$numCopy;i++));
do
(cp -rf $cmdline $cmdline$i; ) &
(echo "preparing folder clone: $i") &
done
wait
this script copies a source folder $cmdline
to (non-existent) destination $cmdline$i
without issue at my pc with Ubuntu 16.04 but when I run same script on a cloud computer with Ubuntu 18.04, it does this:
- duplicates source as destination (I need only this)
- duplicates source into destination too (
destination/source
I don't want this)
this doesn't break any programs but I don't want to consume unnecessary cloud space.
Why would some different version of Ubuntu add a secondary copy into destination folder?
I'm using this script as
./myscript.sh 2 foldertest
this duplicates foldertest as foldertest1 and foldertest2. If first parameter is 32 then it makes 32 copies up to foldertest32.
Documentation of cp says -r is recursive copy which is I need to do full deep cloning of source folder just like copy pasting (in-place where it produces folder2 folder3 ...) in windows or graphical terminal of Ubuntu. Also I add -f to force it copy files without asking because I'm making up to 64 clones and don't want to answer 64 questions if there are already 64 clones.
Some extra info about the behaviour I need:
Folder A: a.txt b.txt c.txt
Folder A1,A2,A3,A4.. to be:
a.txt
b.txt
c.txt
but instead it is:
a.txt
b.txt
c.txt
A
normally when I copy file to file, it overwrites(if it exists). I need same overwrite behavior on folders, not copying into.