Previous code:
total=`ls -Rp rootfs | wc -l`
count=0
When I assign a simple addition to a variable:
sudo find rootfs -exec cp -d -- "{}" "/media/$USER/{}" 2> /dev/null \; -exec sync \; -exec count=$((count+1)) \; -exec echo -en "\rcopiati: $count/$total" \;
I get:
find: ‘count=1’: No such file or directory
Also when I exec:
sudo find rootfs -exec cp -d -- "{}" "/media/$USER/{}" 2> /dev/null \; -exec sync \; -exec count=1 \; -exec echo -en "\rcopiati: $count/$total" \;
I get the same error. Why?
For each file copied i want the counter: 1/13444, that is updated to 2/13444, 3/13444, etc...
edit:
I have found a method but it doesn't see hidden files, how can I make them see them in a for loop?
#!/bin/bash
copysync() {
countfiles() {
for f in $1/*; do
if [ -d "$f" ]; then
countfiles "$f"
else
if [ "${f: -2}" != "/*" ]; then
total=$((total+1))
fi
fi
done
}
recursivecp() {
for f in $1/*; do
if [ -d "$f" ]; then
mkdir -p "/media/$USER/$f"
recursivecp "$f"
else
if [ "${f: -2}" != "/*" ]; then
sudo cp -a "$f" "/media/$USER/$f"
sudo sync
count=$((count+1))
echo -en "\rCopied: $((count*100/total))%"
fi
fi
done
}
total=0
countfiles $1
count=0
recursivecp $1
}
copysync rootfs
sh -c
in-line script? https://unix.stackexchange.com/questions/389705 – Kusalananda Mar 19 '20 at 14:23