LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-28-2012, 05:08 AM   #1
qwertyjjj
Senior Member
 
Registered: Jul 2009
Location: UK
Distribution: Cent OS5 with Plesk
Posts: 1,013

Rep: Reputation: 30
unzip and rename files in zip?


I have about 40 zip files each with a different name. However, the txt file inside each zip is called the same thing File.txt
How can I unzip them all and rename the file inside it so that it does not overwrite each time?
unzip '*.zip' is for the unzipping but the renaming?
Or alternatively, create a folder for each file.
 
Old 05-28-2012, 05:44 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
The easier way is to extract the archive to standard input and redirect it to a file with a custom name, e.g.
Code:
for archive in *.zip
do
  ((i++))
  unzip -p $archive > $(printf "%03d" $i).txt
done
This works if each archive contains only one file.

There is also a -B option that automatically creates a backup copy of files being overwritten and numbers multiple copies of the same file, but you don't have any control on the file names. Instead, if you want to extract a file in a custom directory use the -d option.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unzip all .zip files in a directory tes15 Linux - Newbie 14 08-29-2014 12:46 PM
unzip the zip files to local directory S@R@H Linux - Newbie 5 05-05-2010 09:43 PM
Help to unzip more than one *.zip files SanaJay Linux - Newbie 5 02-10-2009 01:31 AM
Need help to unzip a .zip file with 2 files in it SanaJay Linux - Newbie 3 02-05-2009 03:43 AM
How to Unzip 2 Zip files through one single command sumitarun Linux - Newbie 2 03-23-2005 09:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration