Created
May 22, 2018 16:19
-
-
Save cparmn/1a2c223695df98e6fbf2e17ef985f751 to your computer and use it in GitHub Desktop.
Tallball each folder independently from the currently working directory
This file contains 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 | |
#Casey Parman 5/22/18 | |
#This will archive all directories in the current working directory. | |
# I'm sure theres a more elegant way to do this | |
for i in $(ls -d */); | |
do | |
NAME=$(echo $i | sed 's/\///') #this Removes the tailing forward slash from the variable $i | |
tar -czvf $NAME.tar.gz $i >/dev/null 2>&1 | |
tar -dvf $NAME.tar.gz > /dev/null 2>&1 | |
if [ $? -eq 1 ] | |
then | |
echo "Tarball and Directory do not match, Folder $i has not been removed." | |
else | |
rm -rf $i | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment