-
-
Save Gen2ly/2861046 to your computer and use it in GitHub Desktop.
Archive and compress file and folders
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 | |
# 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