Skip to content

Instantly share code, notes, and snippets.

@cbonesana
Created June 8, 2017 11:38
Show Gist options
  • Save cbonesana/66c69cf8902885bf4a64f2bd7012fe3a to your computer and use it in GitHub Desktop.
Save cbonesana/66c69cf8902885bf4a64f2bd7012fe3a to your computer and use it in GitHub Desktop.
Archive multiple file to each zip with a counter in Ubuntu.
#!/bin/bash
# zip all the files that end in 'sql', creating a zip foreach file
find . -name '*.sql' -print -exec zip '{}'.zip '{}' \; &
# execute a while loop where we compare the old files (number and size) against the zipped files (number and size) with a sleep of 1 second
while true; do clear; echo 'ZIP:'; ls -l *zip | wc -l; du -ch *zip | grep total; echo 'SQL:'; ls -l *.sql | wc -l; du -ch *sql | grep total; date; sleep 1; done
# output:
# ZIP:
# 32
# 2.1G total
# SQL:
# 32
# 12G total
# Thu 8 Jun 13:36:30 CEST 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment