Getting rsync working with pv?

More of a coding question, just need some help with getting a progress bar working during file transfer.

Currently use rsync to transfer files to a target device. While below code works a user is shown an overall percentage of sometimes 200%+.

# copy source to new install
# location of files

# NOF = number of files in AIROOTFS
NOF=$(find ${AIROOTFS} -type f | wc -l)
# transfer files in AIROOTFS to new device, show a progress bar
rsync -a --progress $AIROOTFS $MNT/ | pv -lep -s ${NOF} > /dev/null

Am wondering if ‘du’ is a better option for number of files?

# a version using du....
rsync -av source/ destination/ | pv -p -t -r -s $(du -sb source/ | awk '{print $1}') > /dev/null
1 Like

May need to count links as well?