Operating System - HP-UX
1851080 Members
2203 Online
104056 Solutions
New Discussion

Re: Compressing multiple files using string of a directory

 
SOLVED
Go to solution
rana786
Regular Advisor

Compressing multiple files using string of a directory

Hi all,

I need to compress multiple files of a directory. All files started with the string msc... and ended with the alphabet p or z should have to be compressed. Can anybody help with this issue?
Walker_dhk
5 REPLIES 5
Hemmetter
Esteemed Contributor

Re: Compressing multiple files using string of a directory

Hi Rana

Two solutions:

1) compress single files:

for i in msc*[pz]; do
compress $i
done


2)
create a compressed archive:


# tar cvf - msc*[pz] | compress >msc.tar.Z
# rm msc*[pz]


rgds
hgh
Thummalu
Frequent Advisor

Re: Compressing multiple files using string of a directory

Hi Rana,

go to the directory you want to compress and run the following commands:

tar -cvfp msc-pz.tar msc*[pz]

gzip -9 msc-pz.tar

Thats it

Br
Thummalu
Arunvijai_4
Honored Contributor

Re: Compressing multiple files using string of a directory

# tar -cvf msc.tar msc*
# gzip msc.tar

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
RAC_1
Honored Contributor
Solution

Re: Compressing multiple files using string of a directory

ll msc*(p|z) > file_list
-->Check it lists only the files that you want.
Then
for i in $(cat file_list)
do
compress ${i}
done

There is no substitute to HARDWORK
rana786
Regular Advisor

Re: Compressing multiple files using string of a directory

great
Walker_dhk