LinuxHowTo
How to Copy Files in Linux with a Progress Bar

How to Copy Files in Linux with a Progress Bar

Efficient file copying is vital for Linux users, especially when dealing with large files, backing up data, or moving content across systems. While basic commands like cp get the job done, they lack real-time progress indicators, which can leave you guessing about how long an operation will take.

This guide introduces smarter ways to copy files with visual progress indicators using powerful Linux tools like rsync, pv, tar, dd, and scp. Whether you’re a system admin, DevOps, AI developer, or power user, these tools will help you copy files confidently and clearly.

1. Basic File Copy Using cp command:

The cp command is the default tool for copying files and directories in Linux. It’s fast and widely used, but lacks a progress bar.

Syntax:

cp [options] source destination

Example:

cp file1.txt /home/sohan

Pros: Simple and quick

Cons: No visual feedback, not ideal for large files

2. Copy Files with rsync Showing Progress

rsync is a powerful file synchronization tool that supports incremental transfers and visual progress output. To display progress while copying a file, simply use the --progress flag.

Syntax:

Example:

Sample Output:

ile1.txt
    123,456,789 100%   1.23MB/s    0:00:02 (xfr#1, to-chk=0/1)

Pros:

  • Shows file size, percent complete, speed, ETA
  • Supports local and remote transfers
  • Can resume interrupted transfers

You can add -a for archive mode and -v for verbose output:

rsync -av --progress source/ destination/

3. Visual Progress with PV (Pipe Viewer)

pv lets you monitor the progress of data through a pipeline. It works best when paired with commands like dd or tar. It shows:

  • Progress bar
  • Data transferred
  • Transfer rate
  • ETA (estimated time remaining)

3.1 Copy a File with pv and dd

pv file1.txt | dd of=/opt/file1.txt

Sample Output:

123MB 0:00:01 [123MB/s] [==========================================>] 100%

Use Cases: Disk imaging, large file transfers

3.2 Copy a Directory Using tar and pv

You can also combine tar with pv to monitor the progress of directory transfers.

Syntax:

tar -cf - my-directory | pv | tar -xf - -C /opt/

Explanation:

  • First, tar compresses the directory
  • pv monitors the stream
  • The second tar extracts the contents to the destination

Sample Output:

345MB 0:00:03 [115MB/s] [==========================================>] 100%

This method is perfect for archiving or migrating large directory structures while keeping an eye on the process.

4. Combine rsync with pv for Advanced Progress Monitoring

To take advantage of rsnyc’s robust file transfer logic and pv’s visual progress bar, you can combine them.

rsync -av --progress /mnt/test-directory /opt | pv

Output:

sending incremental file list
file1.txt
    123,456,789 100%   1.23MB/s    0:00:02 (xfr#1, to-chk=0/1)
file2.txt
    234,567,890 100%   2.34MB/s    0:00:01 (xfr#2, to-chk=0/1)
345MB 0:00:04 [86MB/s] [==============================================>] 100%

This approach gives you:

  • Accurate file syncing
  • Speed, time estimates
  • Resume capabilities
  • Real-time progress bar from pv

Best For:

  • Moving or syncing large directories
  • Monitoring backup performance

5. Copy Files Over the Network with ssh and pv

If you’re transferring files or directories to a remote machine over SSH and want a visual progress bar, use pv in combination with ssh and tar. This method is reliable and shows accurate transfer speeds and progress.

Syntax:

pv file1.txt | ssh user@remote 'cat > /destination/path/file1.txt'

Example:

pv file1.txt | ssh root@192.168.1.51 'cat > /root/file1.txt'

Sample Output:

file1.txt
20.0  B 0:00:00 [ 131KiB/s================================================================>] 100%  

Copying a full directory over SSH with a progress bar is best done with tar and pv. This method is both flexible and secure.

Syntax:

tar -cf - my-directory | pv | ssh user@remote 'tar -xf - -C /destination/path/'

Example:

tar -cf - /home/user/my-folder | pv | ssh root@143.110.250.111 'tar -xf - -C /root/

Explanation:

  • The first tar archives the local directory
  • pv adds a real-time progress bar
  • ssh transfers the data securely
  • The remote tar extracts it in place


This method is both flexible and secure.

Conclusion

Efficient file copying with visual progress is crucial in Linux, especially for large files or network transfers. While cp is quick, tools like rsync, pv, tar, and ssh provide real-time feedback, improving control and transparency. By choosing the right tool for your task, you can ensure faster, more reliable file transfers. Integrating these methods into your routine helps eliminate uncertainty, making the file copying process more efficient and predictable.

Leave a Reply

Your email address will not be published. Required fields are marked *