Unzip the Files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unzip the Files
# 1  
Old 10-01-2012
Unzip the Files

I have a list of zip files and regular files in a folder

Code:
/home/data/

Example:
PMExtra_A123_ABC_121001020000.zip
PMExtra_B596_GRT_121001020000.zip
PMExtra_C156_SFD_121001020000.zip
PMExtra_S243_KDF_121001020000.xml
PMExtra_L234_IDF_121001020000.xml

I have to unzip all the .zip files and load into the same folder and remove the .zip files.

.zip files will have the xml files. If the xml file is huge then they zip it. So, how can I unzip all the zip files at a time?

Actually, all the files will be available on a ftp server and since I thought it is hard to put everything in FTP command I thought to put all the files in a local directory and then unzip them.
# 2  
Old 10-01-2012
Have you tried unzip *.zip?

----------------------
Ignore this post. This only works if there is only one .zip file in the current directory.

Last edited by Don Cragun; 10-01-2012 at 07:00 PM.. Reason: Factual error; should have looked at the man page again.
# 3  
Old 10-01-2012
Hi.

The command gunzip can unpack lists of zip files provided they contain only one file:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate comparison between unzip and gunzip.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
edges() { local _f _n _l;: ${1?"edges: need file"}; _f=$1;_l=$(wc -l $_f);
  head -${_n:=3} $_f ; pe "--- ( $_l: lines total )" ; tail -$_n $_f ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C unzip gunzip

pl " Create zipped files:"
./create

pl " Attempt to unzip more than one x.zip with unzip:"
unzip *.zip
ls -lgG t*

pl " Create zipped files:"
./create

pl " Attempt to unzip more than one x.zip with gunzip:"
gunzip -S .zip t*.zip
ls -lgG t*

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
UnZip 5.52 of 28 February 2005, by Debian. Original by Info-ZIP.
gunzip gzip 1.3.12

-----
 Create zipped files:
	zip warning: t1.zip not found or empty
  adding: t1 (stored 0%)
	zip warning: t2.zip not found or empty
  adding: t2 (stored 0%)
-rw-r--r-- 1 142 Oct  1 16:31 t1.zip
-rw-r--r-- 1 144 Oct  1 16:31 t2.zip

-----
 Attempt to unzip more than one x.zip with unzip:
Archive:  t1.zip
caution: filename not matched:  t2.zip
-rw-r--r-- 1 142 Oct  1 16:31 t1.zip
-rw-r--r-- 1 144 Oct  1 16:31 t2.zip

-----
 Create zipped files:
	zip warning: t1.zip not found or empty
  adding: t1 (stored 0%)
	zip warning: t2.zip not found or empty
  adding: t2 (stored 0%)
-rw-r--r-- 1 142 Oct  1 16:31 t1.zip
-rw-r--r-- 1 144 Oct  1 16:31 t2.zip

-----
 Attempt to unzip more than one x.zip with gunzip:
-rw-r--r-- 1 6 Oct  1 16:31 t1
-rw-r--r-- 1 8 Oct  1 16:31 t2

See man pages for details.

Best wishes ... cheers, drl
# 4  
Old 10-01-2012
Sorry about that. I should have said: Try:
Code:
for i in *.zip
do      if unzip $i
        then rm $i
        fi
done

# 5  
Old 10-02-2012
Hey thanks!

I found another command online and this works excellent Smilie

Code:
find /home/data/ -name 'PMExtra*.zip' -exec unzip -d /home/data/ {} \;

Using rm command later to remove the zip files.
# 6  
Old 10-02-2012
find is recursive, so this will not work right if you've got multiple folders of zip files, but for the situation you've given it ought to work yes. Smilie
# 7  
Old 10-02-2012
I am really dummy at unix so I really go with single line commands. I use this commands in the IBM ETL tool.

I do not know how to use
Code:
for i in *.zip
do      if unzip $i
        then rm $i
        fi
done

is i the file name?
like

for filename in filepath ? I have to define the variables right?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

2. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

3. Shell Programming and Scripting

Unzip the .zip file without using unzip utility in UNIX

I have .zip file, i want to list all the files archived in the zip file. unzip utility is not working for me in unix. Please help me resolve this issue Thanks ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

4. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

5. Shell Programming and Scripting

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

6. UNIX for Dummies Questions & Answers

unzip files in a different folder

hi , I am using this command to unzip files from a source unzip -o $source_dir -d $dest_dir butthe problem is that this command creates a new folder at the destination and unzips all the files in that folder. I dont want that extra folder. e.g source_dir= abc/myname.zip... (2 Replies)
Discussion started by: agarwalniru
2 Replies

7. Shell Programming and Scripting

unzip particular gzip files among the normal data files

Hello experts, I run Solaris 9. I have a below script which is used for gunzip the thousand files from a directory. ---- #!/usr/bin/sh cd /home/thousands/gzipfiles/ for i in `ls -1` do gunzip -c $i > /path/to/file/$i done ---- In my SAME directory there thousand of GZIP file and also... (4 Replies)
Discussion started by: thepurple
4 Replies

8. HP-UX

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

9. UNIX for Dummies Questions & Answers

Copy files from CD and Unzip

Hi, I've just installed solaris 9 onto a SPARC box and am connecting to the machine via a console cable using hyper terminal. Unfortunately i have not got a monitor so i'm having to do all my config using the command line (which i'm no good at) I'm trying to copy a patch cluster (ZIP) file... (1 Reply)
Discussion started by: AJD
1 Replies

10. UNIX for Dummies Questions & Answers

unzip .tgz files

hi all How to unzip .tgz files waiting for suggestions Praful (5 Replies)
Discussion started by: Prafulla
5 Replies
Login or Register to Ask a Question