Skip to content

Instantly share code, notes, and snippets.

@boardstretcher
Created March 3, 2017 14:35
Show Gist options
  • Save boardstretcher/2ee1c16903e7bacf14fc952138ff0e76 to your computer and use it in GitHub Desktop.
Save boardstretcher/2ee1c16903e7bacf14fc952138ff0e76 to your computer and use it in GitHub Desktop.
copy with progress bar
#!/bin/sh
cp_p()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
mv_p()
{
strace -q -ewrite mv -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment