LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-04-2010, 11:32 AM   #1
samanp
LQ Newbie
 
Registered: Dec 2005
Posts: 22

Rep: Reputation: 0
find and unzip selected sub folders in tar.gz files


there are few hundred tar.gz files each having several sub dirs in them (ex: ftp_server1_logs, mail_server2_logs). However the main tar.gz files (ex: 20101001.tar.gz) does not contain all sub dirs every time (ex: 20101001.tar.gz may only contain some ftp server log dirs etc..)

what i have to do is find the tar.gz files that contain a specific type of log type (ex: ftp logs) and extract all logs to a single folder (ex: ftp logs)

any help on this (with specific command line options) is highly appreciated.

thanks
 
Old 11-05-2010, 09:16 AM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
I would do something like this (probably not the most elegant, but it works). It needs to be tweaked if you have duplicate filenames within the archives, and will leave you with some empty directories after the extract/move, but should be easy enough to clean up.

Code:
#!/bin/bash

for i in $(ls *.gz)
do
        for j in $(tar -tzf $i | grep "search string")
                do
                        tar -zxvf $i $j
                        mv -v $j output_directory/
                done
done

exit
 
  


Reply



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
BASH: Unzip files/folders from archive one at a time using a loop cade Programming 3 05-16-2010 10:48 PM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
How to unzip files recursively inside folders? jessdog9001 Linux - Software 2 03-22-2006 12:59 PM
is there a simple or easy installer for *.sh files after i unzip *.tar.gz? krt47 Linux - Software 3 07-31-2004 07:38 AM
How to Unzip tar.gz Files in Redhat 7.2 newbie2linux Linux - Newbie 8 12-03-2003 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:40 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
Open Source Consulting | Domain Registration