Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with creating loop and tar file

Status
Not open for further replies.

marcmcconnell

Technical User
Apr 19, 2001
25
GB
I have a question about a loop that I need to create.

I have about 15 directories each containing about 2000-4000 files. I have to create a loop that creates a tar file containing a maximum of 1000 files.

For example directory DIRA contains 2456 files. The loop would create DIRA1.tar containing files 1-1000 in the directory. DIRA2.tar would contain files 1001-2000. DIRA3.tar would contain files files 2001-2456. This would have to happen for all 15 directories (DIRB, DIRC etc..)

I obviously need some sort of a counter and maybe a while loop. Bit of a newbie with loops. Any ideas?
 
Hi

marcmcconnell said:
Bit of a newbie with loops.
No problem. You can help yourself without a proper counter.
man tar said:
-T, --files-from=F
get names to extract or create from file F
[ul]
[li]you list the files in temporary files ( with [tt]ls -1 > listfilename[/tt] )[/li]
[li]split it to to 1000 line chunks ( with [tt]split -l 1000 listfilename[/tt] )[/li]
[li]create archive for the content of each chunk file ( with [tt]tar -c -T chunkfilename archivefilename[/tt] )[/li]
[/ul]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top