Last active
October 18, 2022 13:27
-
-
Save metemaddar/67e815dfe4d777aa891a1b63df1c9902 to your computer and use it in GitHub Desktop.
compare.sh
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 | |
# Original reference: https://www.networkworld.com/article/3538471/how-to-compress-files-on-linux-5-ways.html | |
# ask user for filename | |
echo -n "filename> " | |
read filename | |
# you need this because some commands will replace the original file | |
cp $filename $filename-2 | |
# clean up first (in case previous results are still available) | |
rm $filename.* | |
time tar cvfz ./$filename.tgz $filename > /dev/null | |
ls -l $filename.tgz | |
time zip $filename.zip $filename > /dev/null | |
ls -l $filename.zip | |
time bzip2 $filename | |
ls -l $filename.bz2 | |
# recover original file | |
cp $filename-2 $filename | |
time gzip $filename | |
ls -l $filename.gz | |
# recover original file | |
cp $filename-2 $filename | |
time xz $filename | |
ls -l $filename.xz | |
time 7z a $filename.7z $filename-2 > /dev/null | |
ls -l $filename.7z | |
echo tgz | |
time tar xf $filename.tgz > /dev/null | |
rm $filename | |
echo zip | |
time unzip $filename.zip > /dev/null | |
rm $filename | |
echo bzip2 | |
time bzip2 -d $filename.bz2 > /dev/null | |
rm $filename | |
echo gzip | |
time gunzip $filename.gz > /dev/null | |
rm $filename | |
echo xz | |
time unxz $filename.xz > /dev/null | |
rm $filename | |
echo 7z | |
time 7z e $filename.7z -o$filename-3 > /dev/null | |
# show results | |
# ls -l $filename.* | |
# replace the original file | |
mv $filename-2 $filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment