How to add a progress bar to a shell script?

后端 未结 30 2236
情歌与酒
情歌与酒 2020-11-22 05:48

When scripting in bash or any other shell in *NIX, while running a command that will take more than a few seconds, a progress bar is needed.

For example, copying a b

30条回答
  •  既然无缘
    2020-11-22 06:37

    for me easiest to use and best looking so far is command pv or bar like some guy already wrote

    for example: need to make a backup of entire drive with dd

    normally you use dd if="$input_drive_path" of="$output_file_path"

    with pv you can make it like this :

    dd if="$input_drive_path" | pv | dd of="$output_file_path"

    and the progress goes directly to STDOUT as this:

        7.46GB 0:33:40 [3.78MB/s] [  <=>                                            ]
    

    after it is done summary comes up

        15654912+0 records in
        15654912+0 records out
        8015314944 bytes (8.0 GB) copied, 2020.49 s, 4.0 MB/s
    

提交回复
热议问题