cancel
Showing results for 
Search instead for 
Did you mean: 

tar a series of directories

SOLVED
Go to solution
Vince Fernando
Occasional Visitor

tar a series of directories

How do I tar a series of directories without typing the directory names? As an example, if I have three directories aaa, bbb, ccc I would like to get aaa.tar, bbb.tar and ccc.tar but not a single archived tar.
3 REPLIES
smatador
Honored Contributor
Solution

Re: tar a series of directories

Hi,
perhaps why not with a script
for i in aaa bbb ccc
do
cd $i
tar cvf /tmp/$i.tar .
done
Hope it helps
Vince Fernando
Occasional Visitor

Re: tar a series of directories

Thanks very much smatador. How do I access all the directories in a particular directory for tarring (not just aaa, bbb and ccc)?
Mark S Meadows
Valued Contributor

Re: tar a series of directories

Hi Vince,

In line with the above example :

cd directory_path

for i in `lsf | grep \/ | sed 's/\// /'`
do
tar cvf /tmp/$i.tar $i
done

No doubt there are more elegant ways of ascertaining the sub-directory names to be tar'd in the first line of the for loop, but it is an example.

Regards,

Mark
Administrating HP-UX systems for more years than I care to admit, but still enjoying it (most of the time!).