Skip to content

Instantly share code, notes, and snippets.

@Gen2ly
Created June 3, 2012 02:36
Show Gist options
  • Save Gen2ly/2861046 to your computer and use it in GitHub Desktop.
Save Gen2ly/2861046 to your computer and use it in GitHub Desktop.
Archive and compress file and folders
#!/bin/bash
# Archive and compress file and folders
# Display usage if no parameters given
if [[ -z "$@" ]]; then
#echo " ${0##*/} <file/dir> <*file/dir2> <*name>.tar.xz - archive file/folders"
echo " ${0##*/} <file/dir> <*file/dir2> - archive and compress files and dirs"
exit
fi
# Prompt for filename
while true; do
read -p " Enter archive filename: " filename
if [ -n "$filename" ]; then
break
fi
done
# Check if selection(s) exists
for a in "$@"; do
if [ ! -f "$a" ]; then
echo " Selection \""$@"\" does not exist."
exit
fi
done
# Create archive
tar -c --xz -f "$filename".tar.xz "$@" && \
echo " Created "$filename".tar.xz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment