Skip to content

Instantly share code, notes, and snippets.

@albertogviana
Last active August 22, 2016 12:03
Show Gist options
  • Save albertogviana/00699b49da96fafd6cfb04775b95557d to your computer and use it in GitHub Desktop.
Save albertogviana/00699b49da96fafd6cfb04775b95557d to your computer and use it in GitHub Desktop.
Read a directory and compress files
#!/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