v1ral_ITS

Cp shell script with progress

Apr 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.52 KB | None | 0 0
  1. #!/bin/sh
  2. cp_p()
  3. {
  4.    strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
  5.       | awk '{
  6.        count += $NF
  7.            if (count % 10 == 0) {
  8.               percent = count / total_size * 100
  9.               printf "%3d%% [", percent
  10.               for (i=0;i<=percent;i++)
  11.                  printf "="
  12.               printf ">"
  13.               for (i=percent;i<100;i++)
  14.                  printf " "
  15.               printf "]\r"
  16.            }
  17.         }
  18.         END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
  19. }
Add Comment
Please, Sign In to add comment