Using CheatSheets To Apply Best Practices

CheatSheet: Linux Compress And Decompress

CheatSheet: Linux Compress And Decompress

1.1 Decompress

Name Summary
Unpack *.tar tar -xvf ./file.tar
Unpack *.rar unrar e ./file.rar
Unpack *.zip unzip ./file.zip
Unpack *.gz gunzip ./file.gz; gzip -d file.gz
Unpack *.bz2 tar -jxvf file.tar.bz2 -C /tmp/extract_here/
Unpack *.7z 7z e ./file.7z install p7zip first
Unpack *.xz tar -xf ./file.tar.xz
Unpack *.jar jar -xvf ./file.jar
Unpack *.war jar -xvf ./file.war
Unpack *.tgz tar -xf ./file.tgz

1.2 Compress Common Format

Name Command
Pack to *.tar tar -cvf ./file.tar <dir_to_compress>
Pack to *.gz tar -zcvf ./newfile.tar.gz <dir_to_compress>
Pack to *.tgz tar -cvzf backup.tgz *
Pack to *.bz2 tar -cvf ./file.tar.bz2 <dir_to_compress>
Pack to *.zip zip -r ./file.zip <dir_to_compress>

1.3 Advanced Usage

Name Command
Pack with exclude tar --exclude "*.git*" -cvf file.tar <dir_to_compress>
Remove a single file from tarball tar --delete -f file.tar file1.txt
Add file to tarball. -r indicates append tar -rf file.tar file1.txt


Leave a Reply

Your email address will not be published. Required fields are marked *