LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-17-2012, 12:15 PM   #1
green99
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
script to create tar list and then un-tar using wildcards for lots of directories


Hi All,
I have a bunch of directories that contain tar files. instead of doing all everything manually I want to create a script that cd's into the dir creates a tar list, then extracts only certain file types using --wildcards ... then moves onto the next one

each directory is in numerical order e.g. dir001, dir002, dir003 ....and in each dir the tar files are called tar001, 002 ....

I thought something like "for num in {1..35} ; do cd dir$num ; tar -tf file$num.tar > list.txt ; tar -xf dir$num --wildcards *.bin ; done ..... realise this is wrong but perhaps I am close ?

thanks
 
Old 06-18-2012, 05:08 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
first, you can't do a "cd" inside a loop---each time thru the current directory will be different, so cd will be starting from a different reference point. to iterate through directories (or files) in a directory, just do something like:
Code:
for item in *; do
    stuff
done
or:
Code:
for item in `ls|grep "something"`; do
    stuff
done
Also, look at the man page for tar---eg when specifying the output file (f flag), the syntax to create an archive is eg "tar -cvf <newfilename> <path>"

Finally, if you want to create a bunch of archives, and the just extract certain ones, I wonder if it would be better to have 2 loops?
 
Old 06-26-2012, 04:40 AM   #3
green99
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post
first, you can't do a "cd" inside a loop---each time thru the current directory will be different, so cd will be starting from a different reference point. to iterate through directories (or files) in a directory, just do something like:
Code:
for item in *; do
    stuff
done
or:
Code:
for item in `ls|grep "something"`; do
    stuff
done
Also, look at the man page for tar---eg when specifying the output file (f flag), the syntax to create an archive is eg "tar -cvf <newfilename> <path>"

Finally, if you want to create a bunch of archives, and the just extract certain ones, I wonder if it would be better to have 2 loops?

thanks for you reply, apologies for the delay in replying, your post pointed me in the right direction
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i create .tar.gz,.tar.bz2,.zip file and upload with filezilla=> uncompress? cola Linux - General 1 09-14-2011 01:32 PM
[SOLVED] Using Tar how to Exclude list of directories. anishkumarv Linux - Newbie 3 07-26-2011 03:20 AM
[SOLVED] command for tar'ing multiple sub-directories into a single tar file blainemiller Linux - Server 3 04-21-2011 02:05 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:54 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