- Creating zip
|Zipping of files||zip backup.zip file1 file2 file3||creates a zip containing the 3 files|
|Delete the original file after zip||zip -m mybackup.zip file1||Removes file1 after zipping it into backup.zip|
|Append a file in zip archive||zip -u mybackup.zip file2||Adds file2 to an existing zip mybackup.zip|
|Remove a file from a zip file||zip -d mybackup.zip file1||Removes file1 from mybackup.zip|
|Zipping a Directory recursively||zip -r backupDir.zip dir1/ dir2/||Zips the directories dir1 and dir2|
- Unzip commands
|Basic unzip||unzip mybackup.zip|
|Unzip content in a particular directory||unzip -d /home/directory/ mybackup.zip||Unzips the content into /home/directory/ directory|
|List the contents of the zip file||unzip -l mybackup.zip||lists 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.
|creates a myFile.txt.gz file and the original myFile.txt gets deleted.|
|gunzip myFile.txt.gz||extracts 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 archive||tar -cvf arch.tar *.java||creates 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 file||tar -rvf arch.tar *.html||adds all the “.html” files into existing tar “arch.tar”|
|Extract tar file||tar -xvf arch.tar||extracts the content of “arch.tar” into the current directory.|
-x : Extract the archive
|Extract tar file in specific directory||tar -xvf arch.tar -C /home/directory/||Extracts the content of the tar into directory “/home/directory/”|
|List tar content without extraction||tar -tvf arch.tar||Lists the entire content of the “arch.tar” file|