- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Advanced Copy Command with Progress Bar While Copying/Moving Files in Linux
As a Linux user, you may have found yourself in situations where you need to copy or move large files or directories from one location to another. This process can take some time, and it can be challenging to monitor progress of copy or move operation.
Fortunately, Linux provides several built-in commands that can help you copy or move files efficiently and also monitor progress of operation. In this article, we will discuss advanced copy command with progress bar while copying/moving files in Linux.
What is Advanced Copy Command?
The Advanced Copy (or "cp") command is a built-in Linux command used to copy files or directories from one location to another. This command comes pre-installed on most Linux systems, and it is widely used by system administrators, developers, and Linux enthusiasts.
The cp command provides several options that allow you to customize copy operation, such as preserving file attributes, recursive copying, and more. However, by default, cp command does not provide any progress bar while copying or moving files.
Why do we need a Progress Bar?
When you are copying or moving large files or directories, it can take a considerable amount of time, and it may be challenging to determine how much time is left for operation to complete. This is where a progress bar can be useful.
A progress bar is a graphical representation of copy or move operation's progress. It shows percentage of operation that has been completed and how much time is left for operation to finish. This can be extremely helpful in situations where you need to monitor progress of copy or move operation.
Using "pv" command for Progress Bar
The "pv" command is a Linux utility that can be used to monitor progress of data through a pipeline. This command can be used in conjunction with other Linux commands, such as "cp," to provide a progress bar while copying or moving files.
To use "pv" command with "cp" command, you will need to pipe output of "cp" command to "pv" command. Here's an example −
$ cp -r /path/to/source /path/to/destination | pv -lep -s $(du -sb /path/to/source | awk '{print $1}') >/dev/null
Let's break down command −
"cp -r /path/to/source /path/to/destination" is copy command that copies source directory to destination directory.
The pipe "|" sends output of "cp" command to "pv" command.
"pv" is command that displays progress bar.
"-lep" are options for "pv" command. "-l" enables rate limit, "-e" shows ETA (estimated time of arrival), and "-p" shows progress bar.
"-s $(du -sb /path/to/source | awk '{print $1}')" is option that specifies size of source directory in bytes. This option is required to calculate progress of copy operation accurately.
"/dev/null" redirects output of "pv" command to null device, which discards it.
Using "rsync" Command for Progress Bar
Another command that can be used to copy or move files while displaying a progress bar is "rsync" command. "rsync" command is a powerful utility that can be used to synchronize files between two locations.
To use "rsync" command with a progress bar, you can use "-P" option. Here's an example −
$ rsync -aP /path/to/source /path/to/destination
Let's break down command −
"rsync" is command that synchronizes files between two locations.
"-a" is option that enables archive mode, which preserves file attributes, permissions, timestamps, etc.
"-P" is option that shows progress bar and displays transfer progress, transfer rate, ETA, and more.
Using "bar" Command for Progress Bar
Another utility that can be used to display a progress bar while copying or moving files is "bar" command. "bar" command is a simple utility that displays a progress bar in terminal.
To use "bar" command with "cp" command, you can pipe output of "cp" command to "bar" command. Here's an example −
$ cp -r /path/to/source /path/to/destination | bar
Let's break down command −
"cp -r /path/to/source /path/to/destination" is copy command that copies source directory to destination directory.
The pipe "|" sends output of "cp" command to "bar" command.
"bar" is command that displays progress bar.
In addition to utilities discussed above, there are several other options for displaying progress bars while copying or moving files in Linux. Some of these options include −
"gcp" command − "gcp" command is a wrapper for "cp" command that adds a progress bar to copy operation. This command is not included in most Linux distributions, so you may need to install it manually.
"progress" command − "progress" command is a Linux utility that can be used to display a progress bar for a variety of operations, including copying and moving files. This command can be used in conjunction with other commands, such as "cp" or "mv," to display a progress bar.
"bar-1.11" package − "bar-1.11" package is a set of shell scripts that can be used to display progress bars for various operations, including copying and moving files. This package can be installed on most Linux distributions.
"dialog" command − "dialog" command is a Linux utility that can be used to create dialog boxes and menus in terminal. This command can be used to display a progress bar while copying or moving files.
When choosing a method for displaying progress bars, it's essential to consider factors such as ease of use, compatibility with your Linux distribution, and reliability. While some methods may be more complicated than others, they may also provide more advanced features and functionality.
Overall, displaying a progress bar while copying or moving files in Linux can be an excellent way to monitor progress of operation and estimate time remaining for completion. By using commands and utilities discussed in this article, you can perform efficient file operations and manage your files effectively.
Conclusion
In conclusion, Linux provides several built-in commands and utilities that can be used to copy or move files and also display a progress bar to monitor progress of operation. "pv" command, "rsync" command, and "bar" command are some of utilities that can be used for this purpose.
While copying or moving files, it's always a good practice to monitor progress of operation to ensure that it completes successfully without any errors. progress bar can be an excellent tool to monitor progress and estimate time remaining for operation to complete.
As a Linux user, it's essential to be familiar with these commands and utilities to perform efficient file operations and manage your files effectively.