Tuesday 3 October 2017

batch - Creating separate archives for a set of files


I have directory containing big list of files. I'd like to gzip each file of a certain mask to a separate archive. How do i do that automatically?


For example here's sample directory contents: - index.html - start.html - myfile1.txt - myfile2.txt - myfile3.txt


How to i create separate archive (myfile1.tar.gz,myfile2.tar.gz ...) for each file starting with 'myfile*' ?



Answer



if you use the bash it could look like this



for file in `ls abc_*`; do tar -czvf $file.tar.gz $file ; done

you simply change the "abc_" to your beginning filename.


Be careful it will re compress the already compressed files, because they start like the normal files.


Best regards Kenny


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...