Skip to content

Instantly share code, notes, and snippets.

@ikait
Created August 14, 2014 04:00
Show Gist options
  • Save ikait/3c375e4c69a105b51a2f to your computer and use it in GitHub Desktop.
Save ikait/3c375e4c69a105b51a2f to your computer and use it in GitHub Desktop.
引数で指定したファイル/ディレクトリを、<オリジナルに現在の日時の14桁を付加したファイル名>.zipにzipする
function zipit() {
string_dirpath=$(cd `dirname $1` > /dev/null && pwd)
string_filepath=${string_dirpath}/`basename $1`
echo "Attempt to zip \"${string_filepath}\""
if [ -e $string_filepath ] ; then
echo "It exists!"
string_filename=`basename $1`
date=`date +"%Y%m%d%H%M%S"`
ext=".zip"
$(cd $string_dirpath > /dev/null && zip -9 -r -q "${string_filename}_${date}${ext}" $string_filename)
if [ $? -eq 0 ] ; then
echo "Successfully zipped!"
fi
else
echo "Not found \"$1\". Failed to zip."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment