Zips & Tar

  • Creating zip
Zipping of fileszip backup.zip file1 file2 file3creates a zip containing the 3 files
Delete the original file after zipzip -m mybackup.zip file1Removes file1 after zipping it into backup.zip
Append a file in zip archivezip -u mybackup.zip file2Adds file2 to an existing zip mybackup.zip
Remove a file from a zip filezip -d mybackup.zip file1Removes file1 from mybackup.zip
Zipping a Directory recursivelyzip -r backupDir.zip dir1/ dir2/Zips the directories dir1 and dir2
  • Unzip commands
Basic unzipunzip mybackup.zip
Unzip content in a particular directoryunzip -d /home/directory/ mybackup.zipUnzips the content into /home/directory/ directory
List the contents of the zip fileunzip -l mybackup.ziplists the content of the zip file without extracting it
  • Gzip command

Compresses single file only. GZIP has a higher compression ration compared to normal zip.

Idea is to tar the required files and then gzip the single tar file.

GZIP removes the original file and creates a “.gz” file.

gzip myFile.txtcreates a myFile.txt.gz file and the original myFile.txt gets deleted.
gunzip myFile.txt.gzextracts the original file myFile.txt and myFile.txt.gz file gets removed.
  • Tar command

Stands for Tape Archive used for creating or extracting Archive files. Archive files are used to collect multiple data files together into single file for easier portability & storage.

Create a tar archivetar -cvf arch.tar *.javacreates a “arch.tar” archive file containing all the “.java” files present in the directory.
-c : Creates archive
-v : Verbose information
-f : given filename
Update existing tar filetar -rvf arch.tar *.htmladds all the “.html” files into existing tar “arch.tar”
Extract tar filetar -xvf arch.tarextracts the content of “arch.tar” into the current directory.
-x : Extract the archive
Extract tar file in specific directorytar -xvf arch.tar -C /home/directory/Extracts the content of the tar into directory “/home/directory/”
List tar content without extractiontar -tvf arch.tarLists the entire content of the “arch.tar” file

Leave a Comment