0

I have a folder cnt, where inside I have

a/estimate.txt
a/otherFolder/....
b/estimate.txt
b/otherFolder/...
...
z/estimate.txt
z/otherFolder/..

I want to have a zip containing

a/estimate.txt
b/estimate.txt
...
z/estimate.txt

Currently I am using zip -r cnt.zip cnt which zip many things include otherFolder that I don't want.

How to achieve of what I mention in question?

2
  • From you question, it looks as though the files you want to zip are no farther than one layer down. Is this correct? Apr 12, 2015 at 0:47
  • @cremefraiche yes it is correct!
    – william007
    Apr 12, 2015 at 0:52

2 Answers 2

1

It looks like you only need the estimate.txt files in the 1st level subfolders of cnt.

You can use wildcards to do this; just run zip -r cnt.zip cnt/*/estimate.txt.

Here's an example:

$ ls -R cnt
cnt:
a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z

cnt/a:
estimate.txt  otherfolder

cnt/a/otherfolder:
file1  file2

cnt/b:
estimate.txt  otherfolder

cnt/b/otherfolder:
file1  file2

...

cnt/y/otherfolder:
file1  file2

cnt/z:
estimate.txt  otherfolder

cnt/z/otherfolder:
file1  file2

$ zip -r cnt.zip cnt/*/estimate.txt
  adding: cnt/a/estimate.txt (stored 0%)
  adding: cnt/b/estimate.txt (stored 0%)

...

  adding: cnt/y/estimate.txt (stored 0%)
  adding: cnt/z/estimate.txt (stored 0%)
1

Try this:

find /full/path/to/cnt/ -type f -name "estimate.txt" -exec zip -r cnt.zip {} +
1
  • 1
    Nice, first thing that came to my mind was a for-loop. This is much cleaner. Apr 12, 2015 at 0:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .