Last active
August 22, 2016 12:03
-
-
Save albertogviana/00699b49da96fafd6cfb04775b95557d to your computer and use it in GitHub Desktop.
Read a directory and compress files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
path=${1} | |
glob_filename=${2} | |
if [ ! ${path} ] || [ ! ${glob_filename} ] | |
then | |
echo "This script will compress files using zip. | |
To use this script you need to inform the directory path and the file | |
./compress_files.sh directory 'files' | |
For example you can zip all files starting with my_report_2016*.csv: | |
./compress_files.sh /data/my-data 'my_report_2016*.csv' | |
" | |
exit 1 | |
fi | |
cd $path | |
echo `pwd` | |
find . -iname "${glob_filename}" -print0 | while read -d $'\0' file | |
do | |
filename=$(basename $file) | |
echo "Compressing $filename" | |
zip -m $filename.zip $filename | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment