Cp command with progress bar for Linux

In Linux default cp command does not show any sorts of progress [bar] when you try to copy the file. This matter sometimes get annoying particularly when you use command line extensively to copy big and huge files over. At least this for me is kind of big matter. Therefore, I did little bit search on the internet to find a solution and found the following suggestions,

1. Using pv command

Pv could be a good replacement for cp and installation is quite easy in Ubuntu but you should know if you use this command all file permissions and ownerships would be gone so be careful on use it. In order to install it just type following command,

$ sudo apt-get install pv

2. Using cp with some Bash script

In this solution you need to use the following Bash script and you should copy this file over to /bin/ folder in order to be accessed globally and easy like cp command. The script source code is in the following section,

#!/bin/sh
# SCRIPT:  copyx ver 1.0, 14-9-2011
# PURPOSE: Copies files and shows the progress of copying.
# Usage Example: ./copyx my100gbfiles.tar.gz /path/to/destination/my100gbfiles.tar.gz
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
cal += $NF
if (cal % 10 == 0) {
percentage = cal / totalsize * 100
printf "%3d%% [", percentage
for (i=0;i<=percentage;i++)
printf "="
printf ">"
for (i=percentage;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' totalsize=$(stat -c '%s' "${1}") cal=0

3. Using rsync command

Rsync command is another replacement for cp command which equipped with progress bar and speed indicator which personally I highly recommend  it.

$ rsync -avh --progress [Source] [Dest]

4. Using gcp command

Gcp is also another command that can be used instead of cp. You can install gcp in Ubuntu with the following command,

$ sudo apt-get install gcp

Send your idea and information to kasra@madadipouya.com

Leave a Reply