Create unique tar archives from a list of directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create unique tar archives from a list of directories
# 1  
Old 05-16-2011
Create unique tar archives from a list of directories

I'm looking to archive a client directory from a CIFS share

There are multiple directories that will be stored in a text file and I'm looking to
create an individual tar archive of each folder in the directory.

I've tried a number of commands to no avail.

Here's what I would like.

text file contents
Code:
dirA
dirB
dirC

output:
Code:
dirA.tar
dirB.tar
dirC.tar

This command appears to work but the tar file isn't created in my current directory.
Code:
for i in `cat textfile`; do tar cvf $i.tar $i; done

*Update*
I did some more testing while typing this and figured out that if I change $i.tar to test.tar, the archive is created. I would like the archive to have the name of the directory that is being archived.

Any ideas of a better way to accomplish this?

Last edited by Franklin52; 05-16-2011 at 02:59 AM.. Reason: Please use code tags
# 2  
Old 05-16-2011
It worked fine for me in Linux. May be you could try using the current directory path as below

Code:
 for i in dir{1..4} ; do tar cvf  ./$i.tar ./$i; done

# 3  
Old 05-16-2011
Thanks but my problem is that the text file contains directories in other filesytems. When I run this script, it's creating the tar within the directory it's tarring.

Code:
for i in `cat textfile`; do tar cvf $i.tar $i ; done

I want it stored in my current directory. So when I change it point to my current directory, i get an error.

Code:
for i in `cat textfile`; do tar cvf ./$i.tar $i ; done
tar: .//path/to/directory.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

Anyone?

---------- Post updated at 08:10 PM ---------- Previous update was at 07:45 PM ----------

I got the solution...

Code:
for i in `cat textfile.txt`; do tar -cf ${i##*/}.tar $i; done


Last edited by Franklin52; 05-17-2011 at 03:34 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create a long list of directories with mkdir?

Hi... Thanks to read this... I want to use mkdir to create many directories listed in a text file, let's say. How do I do this? Sorry for this maybe very basic question :) (13 Replies)
Discussion started by: setub
13 Replies

2. Shell Programming and Scripting

Copy of "How to create a long list of directories with mkdir?"

To bakunin and corona688: My result when text in file is ms_ww_546 ms_rrL_99999 ms_nnn_67_756675 is https://www.unix.com/C:\Users\Fejoz\Desktop\ttt.jpg I hope you can see the picture. There is like a "whitespace character" after 2 of the 3 created directories. ---------- Post... (0 Replies)
Discussion started by: setub
0 Replies

3. Shell Programming and Scripting

Scan directories and create a list of files

Gents, Please can you help. I want to create a list which contends the complete patch of the location of some directories with the size of each file. need to select only .txt file In this case I am try to find the subdirectories tp1 and tp2 and create the output list. jd175-1 tp1... (3 Replies)
Discussion started by: jiam912
3 Replies

4. Shell Programming and Scripting

Tar archives monthly

Hi, I want to archive files by month, is there anyway of this code looks better? find /tmp/w/ -type f -newermt '2014-01-01' ! -newermt '2014-02-01' | xargs tar -czvf files01.tar find /tmp/w/ -type f -newermt '2014-02-01' ! -newermt '2014-03-01' | xargs tar -czvf files02.tar find... (9 Replies)
Discussion started by: prpkrk
9 Replies

5. UNIX for Advanced & Expert Users

Multi-Volume tar archives. [solved]

Hi, The only off-line storage medium I have is DVD. I am trying to back up around 10G of data and if I can achieve a practical solution I will use it more generally. I am currently considering something along the lines of: tar --create --multi-volume --tape-length=nnnn <pathspec> |... (0 Replies)
Discussion started by: MikeGM
0 Replies

6. OS X (Apple)

Decompressing Tar Archives (Finally!)

If you've come across this problem with unzipping/decompressing zips, you might find this helpful: I was having a little trouble with unzipping (decompressing) tarred archives under OS 10.5 until today. My first attempt was to just simply double-click on the zip file (i.e., example.tar.gz) and... (2 Replies)
Discussion started by: unimachead
2 Replies

7. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

8. UNIX for Dummies Questions & Answers

segmenting tar archives

assuming i need to create a tar archive which would turn out to be bigger than 2gb, how could i segment the archive into say, 1 gb parts? (3 Replies)
Discussion started by: crudealien
3 Replies

9. UNIX for Dummies Questions & Answers

tar archives

I have a tar archive which I believe may be corrupted, produced on an HP-UX 10.x box and written to a 4mm DDS-3 tape. I understand that gnu tar has a -W (--verify) option which will attempt to verify the archive after it has been created. Am I right in saying that this option cannot be used to... (4 Replies)
Discussion started by: sam_pointer
4 Replies
Login or Register to Ask a Question