Search This Blog

Sunday 1 March 2020

How to tar/untar , zip/unzip a file or directory in Linux Server

Frequently working in BI Administration, we would work on packing/unpacking the tar and zip files for installation, patching or packing the old files as backup. This command is handy and useful:

To Unpack/Untar the tar.gz file:

syntax: tar - xvzf <zip_or_tar.gz_file_Name>
e.g.: tar -xvzf  java8u251.tar.gz

The above command will untar  the java8u251.tar.gz file.

To Pack/Tar the file or directory:

Syntax: tar -cvzf <target_file_name> <source_file_Or_Directory_Name>
e.g.: tar -cvzf  jdk1.8_241.tar.gz  jdk1.8_241

How to unpack .zip file:

Unzipping in the same directory where the zip file is:
Syntax: unzip <Source_Zip_File>
e.g: unzip

Unzipping the file to a particular directory:
Syntax: unzip <source<zip_file> -d <target_directory_to_unzip>
e.g: unzip -d \home\music

How to pack .zip file:

zipping the directory:
Syntax: zip -r <target_zip_file_name> <Source_Directory>
e.g: zip -r /home/music

Zipping a file
zip names.txt

How to Unpack .zip file:
Unzipping the file to a particular directory:
Syntax: unzip <source<zip_file> -d <target_directory_to_unzip>
e.g: unzip -d /home/music

To unzip within the same directory, use the without -d

You can encrypt .zip with a password by passing the -e option:
zip -r -e /home/music

Verify file with the ls command:
ls -l

This is the meaning for each letter in -xvzf or cvzf 

  • -x: Extract, retrieve the files from the tar file.
  • -v: Verbose, list the files as they are being extracted.
  • -c: Create, Create a tar or zip file
  • -z: Zip, use gzip, zip or tar.gz to decompress the tar file.
  • -f: File, the name of the tar file we want tar to work with. 

No comments:

Post a Comment

What is Oracle Database Link and How to create database link (DB Link)

Recent Posts