24

A fixed-length progress bar, a file or byte count, or better yet a timer showing the estimated time remaining would be ideal.

zip's standard behavior seems to be to print a line for every file processed, but I don't want that information overload when I zip thousands of files. I want a guesstimate how long it's going to take.

I tried the -q (--quiet) option in combination with -dg (--display-globaldots) but that just floods stdout with multiple lines of dots and gives no useful indication.

I also tried -qdgds 10m as mentioned in the man page, but got the same result.

I then tried -db (--display-bytes) and -dc (--display-counts) but there doesn't seem to be a global option, so it again prints it for every filename.

Lastly, I tried it together with -q like -qdbdc, but that just outputs nothing.

Funnily enough, I found a man page on the info-zip site that mentions a -de (--display-est-to-go) option which should "Display an estimate of the time to finish the archiving operation."

That sounds exactly like what I want, but the problem is that my version of zip does not have that feature. I'm using Ubuntu 14.04.1 64bit, bash-4.3.30(1) and zip-3.00. According to Wikipedia, this is zip's latest stable release.

There are unreleased beta versions on the info-zip sourceforge page, but I'd rather not entrust my data to a beta release.

  • Log the output to a file and use it to provide high level info with tee. Before starting zip, make a total count of the files (with ls or find -type f) and while it is zipping, read the log file for the number of lines of processed files it already has (with grep for the right lines to look at, and wc -l for the lines count), so your high level info will show something like "234/76438 files processed"; – Aquarius Power Apr 27 '15 at 1:35
  • you can work the timing by considering the total files size and checking the size of the ones that were already processed; but... even files with the same size take different time to be processed so it will always be a wild guess... – Aquarius Power Apr 27 '15 at 1:40
  • I don't know if you can use stdin when making ZIP files, but if gzip is okay, you can do something like pv /path/to/file | gzip > /path/to/file.gz – DopeGhoti Jul 28 '15 at 23:51
11

zip can compress data to standard output. Hence, you can combine it with other tools like pv:

zip -qr - [folder] | pv -bep -s $(du -bs [folder] | awk '{print $1}') > [file.zip]

Remove one of the -bep options as your convenience.

  • Thanks for this! I do this on my mac (brew install pv, brew install coreutils, and replace du with gdu). – Jeff Oct 26 '17 at 13:46
3

If you're ok with using 7z:

7z a output.zip folder/

This will give you a progress bar like this:

Open archive: test.zip
--
Path = test.zip
Type = zip
Physical Size = 232039663

Scanning the drive:
3 folders, 2401 files, 238122225 bytes (228 MiB)

Updating archive: test.zip

Items to compress: 2404

 16% 279 U folder/file.txt  
1

I have used successfully the following:

zip -r [target_zip] [folder_to_zip] 2>&1 | 
pv -lep -s $(ls -Rl1 [folder_to_zip] | egrep -c '^[-/]') > /dev/null

And this is explained below:

zip -r [target_zip] [folder_to_zip] 2>&1 |

zip recursively into [target_zip] file the [folder_to_zip] redirecting stderr to stdout. Note, that stderr will contain one line for each file and directory being processed.

pv -lep -s $(ls -Ral1 [folder_to_zip] | egrep -c '^[-/]') > /dev/null

pipe into pv the lines with the filenames as they are being output from zip. pv is operated in line mode (counting progress based on lines and size is also in number of lines to expect - see PV man page -l option).

The total size of lines to expect is gathered by recursively listing (ls) the [folder_to_zip] and counting the lines starting with '-' or 'd' i.e. all the files and directories (remember directories are listed starting with '/' ).

The above provides accurate percentage of completion as the 100% is reached when all files and directories have been processed.

The problem with the answer of pedroapero is that progress is calculated on number of bytes processed (compressed) over the total number of bytes to process (uncompressed). As a result the process will complete at around 30% (depending on the compression rate).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.