Skip to content

Instantly share code, notes, and snippets.

@Monmoy042
Last active August 3, 2021 14:49
Show Gist options
  • Save Monmoy042/fa139ed5e8d4fcc7921857ad6d836900 to your computer and use it in GitHub Desktop.
Save Monmoy042/fa139ed5e8d4fcc7921857ad6d836900 to your computer and use it in GitHub Desktop.

File Archive and Compression in Linux

Arhive Utility

tar -cvf [newDirectoryName].tar [directoryName]
Exp: tar -cvf archiveEtc.tar etc

Extract Archived Directory

tar -xvf [archivedDirectoryName]
Exp: tar -xvf archiveEtc.tar

Archive + Compression in gz

tar -czvf [newDirectoryName].tar.gz [directoryName]
Exp: tar -czvf archivedEtc1.tar.gz etc

Extract gz format directory

tar -xzvf [archivedDirectoryName].tar.gz
Exp: tar -xzvf archivedEtc1.tar.gz 

Archive + Compression in bz2

tar -cjvf [newDirectoryName].tar.bz2 [directoryName]
Exp: tar -cjvf archivedEtc2.tar.bz2 etc

Extract bz2 format directory

tar -xjvf [archivedDirectoryName].tar.bz2 
Exp: tar -xjvf archiveEtc2.tar.bz2

Archive + Compression in xz

tar -cJvf [newDirectoryName].tar.xz [directoryName]
Exp: tar -cJvf archivedEtc3.tar.xz etc

Extract xz format directory

tar -xJvf [archivedDirectoryName].tar.xz
Exp: tar -xJvf archiveEtc2.tar.xz

File Compression

gzip file1
bzip2 file2
xz file3

Extract Files

gunzip file1.gz
bunzip2 file2.bz2
unxz file3.xz

Extra things

tar -cvf allfiles.tar file1 file25 file3
tar -tvf allfiles.tar ---> View contents

Archive all the contents in a new directory
------------------------------------------
mkdir new
tar -xvf allfiles.tar -C new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment