tar, zip multiple separate directories and move the results to another volume


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar, zip multiple separate directories and move the results to another volume
# 1  
Old 03-10-2009
tar, zip multiple separate directories and move the results to another volume

TIA,

I'm using FreeBSD 6

I have a series of Directories (A,B,C,...Z). Each directory has files and other directories within it.

I want to compress the contents of each top directory into a single file so that I get an archive of each directory (for example, A.gzip) AND and want to move that compressed file to another volume on the system.

I have managed to be able to gzip the contents of each directory, but end up with a complete directory structure full of .gzips.

Looking on here I see that tar appears to be able to create the single-file archives I want, but I cannot tell if tar will compress and combine the files AND put the finished results on the other volume.

Ideas? Thanks again,

johnC
# 2  
Old 03-10-2009
tar wont compress but will create an archive, you just have to gzip it after and you will find yourself with a <my_archive>.tar.gzip file
easy no?
# 3  
Old 03-10-2009
Thanks, but how do I get all that into one command?

"Hi there, tar! Will you please make an archive of Volume_Source/Directory_A, then gzip it for me and save the results on Volume_Target/?"

would this work:

Code:
tar -czf /Volumes/Volume_Target/A.tar.gz /Volumes/Volume_Source/Directory_A

?
# 4  
Old 03-11-2009
Does your implementation of "tar" have a -z flag? If yes, then the above should work.
# 5  
Old 03-11-2009
Thanks for the confirmation. I tried it when I got home last night and it did work. Now I just need to find a way to automate this command to run on each directory individually. I mean, tar and gzip Directory A to Volume B, then tar and gzip directory B to Volume B, then tar and gzip Directory C to Volume B and so on.... Is this a shell script thing? I have tried to understand the various options under tar or gzip but I don't see that sort of intelligence in the options....

TIA,

johnC
# 6  
Old 03-11-2009
Yes this is a shell script thing...
You will need a loop:
Code:
something like
for i in A B C D...
do
   cd  $i
   tar -c ...
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Tar extract a multiple directories

i extract it through script, is there any way to script or automate to tar extract a tarfiles in multiple directories at once? Cannot open: No such file or directory tar: Error is not recoverable: exiting now for dir in `ls -d /tarfiles/*/ | sed 's/.$//'` do rm -f $dir/*.tar mv -f... (1 Reply)
Discussion started by: kenshinhimura
1 Replies

4. Shell Programming and Scripting

Extract a tar ball into multiple directories

#cat a BAC064DAL BAC063DAL BAC056PHX BAC066DAL BAC062PHX BAC062DAL BAC060DAL BAC058PHX BAC054PHX BAC051PHX # for i in `cat a` > do > tar xvf $a/$a*.tar* > done tar: /*.tar*: Cannot open: No such file or directory tar: Error is not recoverable: exiting now tar: /*.tar*: Cannot... (3 Replies)
Discussion started by: kenshinhimura
3 Replies

5. UNIX for Dummies Questions & Answers

Using tar to move directories

I have figured out how to create a tar file that holds all the files in a particular directory. The plan is to move the tar to a new system via FTP so that we can test the new system with our files and libraries. What I can't figure out is how to unzip the tar file; I keep getting messages that... (8 Replies)
Discussion started by: KathyB148
8 Replies

6. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

7. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

8. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

9. Shell Programming and Scripting

Matching a string (zip code) from a list in a separate file

I have a list of postal addresses and I need to pull the records that match a list of zip codes in a separate file. The postal addresses are fixed width. The zip code is located in character position 149-157. Something better than: cat postalfile.txt | grep -f zipcodes.txt would be great. $... (8 Replies)
Discussion started by: sitney
8 Replies

10. BSD

tape drives vs. tar with multiple directories

Hello, I have a little problem with backup & restoring files from tape drive. I am adding 3 directories to my tape, and it is OK: hades# tar -cvf /dev/nsa0 test test1 restore a test a test/level1 a test/myharddisk.img a test1 a test1/level1 a test1/myharddisk.img a test1/test.img a... (1 Reply)
Discussion started by: d3m00n
1 Replies
Login or Register to Ask a Question