Home » 2016 » December » 25 » Guide for working with zipped and archived files in Linux/AIX

4:26 PM
Guide for working with zipped and archived files in Linux/AIX
  • Hello Guys, today we shall practice some commands that are frequently used to analyse the zipped and/or archived files in open system
  • These command can help you greatly to work with *.gz, *.zip, *.tar files . 
  • I have collected some examples from my work experience that can be helpful to dig into such files.

1. Just list out the files inside a ZIP

Below is the command that will show what are the files present inside the ZIP without actually unzipping them.

shanky@portal:[UAT]:>unzip -l TDS.HDGFF5163725.zip
Archive:  TDS.HDGFF
5163725.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       98  10-25-2016 16:38   TDS.N1.CC161025163725.csv
   498306  10-25-2016 16:37   09JHP16G134Yz337GH02.pdf
   440093  10-25-2016 16:37   09JHP16G229Yz137GH02.pdf
---------                     -------
   938497                     3 files


2. Look into one such file inside a ZIP

So, the below example shows how we can look/search in a file that is there inside the zip. We have one *.csv file inside the zip, we can show that zip file or grep some pattern from that csbv file.


shanky@portal:[UAT]:>unzip -c TDS.HHH.161025163725.zip *.csv
Archive:  TDS.HHH.
161025163725.zip
  inflating: TDS.HHH.1.CC161025163725.csv
SEQUENCE;PDFFILENAME;PAGES
1;09JHP16G229Yz137GH02.pdf;14
2;09JHP16G134Yz337GH02.pdf;34
FILEEND;48

Here, -c option is used to list the files from an archive on to console.

Similarly, lets say there is pdf file called some.pdf, we can look into that pdf and this all can be done without actually unzipping the archive.


shanky@portal:[UAT]:>unzip -c TDS.HHHH.1025163725.zip some.pdf|head
Archive:  TDS.HHHH.1025163725.zip
  inflating: some.pdf
%NADF.1.9
%õäöü

some

data
/Type /XObject
/Subtype /Image
/Name /I1

 


Ok, lets play with gunzipped files, 

3. Look into *.gz file without de-compressing.

 

shanky@portal:[UAT]:>gzip -dc TDS.HHHH.1.D0412T151915.tar.gz|head
TDS.HHHH.1.D0412T15.ind100664 000356 000312 00000001116 12703120670 017612 0ustar00s COMMENT: CODEPAGE only need to define once in the IND file
CODEPAGE:850
some data

alkfhs

sfkl

 

4. Show or GREP for some pattern from a gunzipped file

We can directly grep from a *.gz file using zgrep as below:

shanky@portal:[UAT]:>zgrep GROUP_FIELD_NAME TDS.HHHHH.412T151915.tar.gz
GROUP_FIELD_NAME:repid
GROUP_FIELD_NAME:rdate
GROUP_FIELD_NAME:noabcd
GROUP_FIELD_NAME:shdfe
GROUP_FIELD_NAME:sdhf
GROUP_FIELD_NAME:jjjj

similarly, use zmore command to display the content of it.

shanky@portal:[UAT]:>zmore TDS.WMCSTMT.HLD.ESTMT1.D160412T151915.tar.gz|tail

trailer <<
/Info 1 0 R
/Root 2 0 R
/ID[<bjskhg98wetywc0fe5d><bdslgfh3897fe5d>]
/Size 42
>>
startxref
363183
%%EOF


5. List out the files from a tar archive.

We can see what are the files inside a TAR, without extracting files from it.

shanky@portal:[UAT]:>tar -tvf TD.SHHHH.25T163725.tar|head
-rw-rw-r-- 238 202    7611 Oct 25 16:38:51 2016
TD.SHHHH.25T163725.ind
-rw-rw-r-- 238 202  485826 Oct 25 16:37:38 2016 07gg36Yz737GH02.pdf
-rw-rw-r-- 238 202  482757 Oct 25 16:37:40 2016 07J44G138Yz137GH04.pdf
-rw-rw-r-- 238 202  303580 Oct 25 16:37:42 2016 08zzdf6E242A0YB037zz.pdf
-rw-rw-r-- 238 202  759608 Oct 25 16:37:29 2016 08zzJHhhg16E226D0YB037zz02.pdf

 


 

6. Search or display a *.tar.gz file without making any change to it.

Here we are using gzip -dc <file> to list the files from *.gz and later we are using tar -tvf on to the output of gzip command.

So, gzip -dc *.tar.gz|tar -tvf - |head  , if the file is *.tar.gz

tar -tvf *.tar  if the file is *.tar.

shanky@portal:[UAT]:>gzip -dc TDS.HHH.412T151915.tar.gz|tar -tvf - | head
-rw-rw-r-- 238 202     590 Apr 12 15:20:24 2016
TDS.HHH.412T151915.tar.gz.ind
-rw-rw-r-- 238 202  364190 Apr 12 15:19:18 2016 09DAO16z317LD319CH02.pdf


 

Please note that gunzipping a zipped does not yield much space so its not a good practice. See the below exampel to understand.

shanky@portal:[UAT]:  >ls -l abccc347558.zip
-rw-rw-r--    1 shanky  strsgrp      666367 Oct 25 16:38 abccc347558.zip

Compression:
shanky@portal:[UAT]:  >gzip -v abccc347558.zip
abccc347558.zip:   0.1% -- replaced with abccc347558.zip.gz
shanky@portal:[UAT]:  >ls -l abccc347558.zip*
-rw-rw-r--    1 shanky  strsgrp      665441 Oct 25 16:38 abccc347558.zip.gz

Lets decompress it back to *.zip file.

shanky@portal:[UAT]:  >gzip -d abccc347558.zip.gz
shanky@portal:[UAT]:  >ls -l abccc347558.zip
-rw-rw-r--    1 shanky  strsgrp      666367 Oct 25 16:38 abccc347558.zip


7. Look into a compressed file using zcat.

shanky@portal:[UAT]:  >compress aklaf634724.txt

shanky@portal:[UAT]:  >ls -l aklaf634724.txt*
-rwxrwx---    1 shanky  strsgrp          93 Jun  1 2016  
aklaf634724.txt.Z


shanky@portal:[UAT]:  >zcat aklaf634724.txt
TDS.WMCSTMT.FRN.IN1.CC160601152938.zip
TDS.WMCSTMT.LOC.BC1.CC160601152938.zip
TDS.WMCSTMT.LOC.IN1.CC160601152938.zip



shanky@portal:[UAT]:  >zcat aklaf634724.txt.Z
TDS.WMCSTMT.FRN.IN1.CC160601152938.zip
TDS.WMCSTMT.LOC.BC1.CC160601152938.zip
TDS.WMCSTMT.LOC.IN1.CC160601152938.zip

 
 

Category: Open System-Linux | Views: 810 | Added by: shanky | Tags: TAR, compression, zip, Archive, unzip, GZIP | Rating: 5.0/1

Related blogs


You may also like to see:


[2015-06-16][Open System-Linux]
Alien command : convert files from one form to another, install binary packages
[2014-12-05][Open System-Linux]
PIDSTAT command for debugging and analysis of Performance of Linux process
[2015-07-12][Open System-Linux]
EGREP or extended grep in Linux to search patterns
[2014-09-21][Open System-Linux]
How to define command prompt strings in Linux : what are $PS1, $PS2, $PS3 and $PS4?
[2014-03-11][Open System-Linux]
STRINGS : a command in linux to read the non-text files

Total comments: 0
avatar