Skip to content

Instantly share code, notes, and snippets.

@Ohcanep
Created March 26, 2016 06:36
Show Gist options
  • Save Ohcanep/cbc3337981248afe83bd to your computer and use it in GitHub Desktop.
Save Ohcanep/cbc3337981248afe83bd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
E_NUMARGS=1
E_NOTDIR=2
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` [DIRECTORY]"
exit $E_NUMARGS
fi
if [ ! -d $1 ]; then
echo "No such directory"
exit $E_NOTDIR
fi
suffix=$(date +%Y-%m-%dT%H-%M-%S%z)".tar.gz"
filename="$1_$suffix"
echo "Archiving $1 ..."
tar -cvzf $filename $1
if [ $? -eq 0 ]; then
echo "Archive $filename created."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment