Zip Multiple Text Files from Multiple Directories into One ZIP File in One Command in Bash

2

I have an account on AWS and I use S3 for storing data. I have commands that will enable me to zip data files like so:

data.zip s3_dir/level-1/level-2/*/*/data.txt

But there are, say, 50 or more levels. I want to zip all the data.txt files together from all levels. I'm not as sharp on my Bash as I could be so any help would be much appreciated.

nicorellius

Posted 2011-04-18T22:14:09.540

Reputation: 5 865

does it have to be a zip file? Can you use gzip instead? It's not the same format, but I know it can be recursive with the -r option...

– beatgammit – 2011-04-18T22:36:09.983

Answers

3

find some/dir -name data.txt | zip -@ data.zip

Ignacio Vazquez-Abrams

Posted 2011-04-18T22:14:09.540

Reputation: 100 516

This is perfect... Actually, right after I posted this question, a buddy gave me some hints... The command I used was: find /some/path -name '*.txt' | xargs -n 100 zip all_data.zip – nicorellius – 2011-04-18T22:39:04.317

What's the -@ for BTW? – nicorellius – 2011-04-18T22:39:52.537

It tells zip to get the list of filenames from stdin, so that you don't need to use xargs. – Ignacio Vazquez-Abrams – 2011-04-18T22:40:43.130