If you divide your tasks into two steps, first, you divide and save the filenames of the bigger drive into two files. To alternate between the different files, a simple modulus is used which gives us 0
, 1
, 0
, 1
the number is used to resolve the file used for the filenames, .e.g, 0
resolves names_0.txt
and so on. The file list should only contain all end nodes (files, links, and empty folders) and no starting point. For the last part cpio
is used instead of moving the files (I believe copying does not put as much strain on the heart as mv does). The same principle is used to resolve the targets for cpio
.
#!/bin/bash
a=0
b=$PWD
c=$b/source
declare -A A=( \
[0]=$b/names_0.txt [1]=$b/names_1.txt [$b/names_0.txt]=$b/mnt/target_0 [$b/names_1.txt]=$b/mnt/target_1 \
)
rm -f "${A[0]}" "${A[1]}"
# 0,1,0,1
while IFS= read -rd ''; do # â
printf %s\\0 "$REPLY" >> "${A[$((++a % 2))]}"
# â
# $b/names_0.txt, $b/names_1.txt
done < <(find "$c" \( \( -type d -empty \) -o ! -type d \) -printf %P\\0 | sort -zV)
# $b/names_0.txt, ...
# â
for d in "${A[0]}" "${A[1]}"; do
# $b/mnt/target_0
# â
cpio -0 -pvdm -D "$c" "${A[$d]}" < "$d"
done # â
# $b/names_0.txt
I used a simple install script to generate a test example:
#!/bin/bash
a=0
for i in source/{a..z}/{0..20}; do
install -D /dev/null $i/file_$((++a)).txt
done
mkdir -p mnt/target_{0..1}