0

I have a very messy folder which contains thousands of files and directories. I would like to create a Zip file which only contains some of the folders (and files within those folders) - specifically those folders which have number-only names (104, 2342, etc...).

I can't figure out how to do this though - any suggestions?

I'm on Linux - CentOS to be exact :)

Professor Frink
  • 529
  • 4
  • 7
  • 15

2 Answers2

1

Does this work for you:

 zip -ry archive.zip [0-9]*

Run on a directory containing this:

001  002  100  200  aaa  bbb

it creates a zip archive of only the numbered directories:

$ unzip -l archive.zip 
Archive:  archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2010-10-19 22:27   001/
        0  2010-10-19 22:27   002/
        0  2010-10-19 22:41   100/
        0  2010-10-19 22:41   100/10000/
        0  2010-10-19 22:41   100/10000/a.txt
        0  2010-10-19 22:41   100/10000/10000.txt
        0  2010-10-19 22:27   200/
---------                     -------
        0                     7 files

That is only numbered files/dirs at the top level get put in the zip archive.

UPDATE To exclude files from the top level:

find . -maxdepth 1 -type f > excluded.files

review 'excluded.files' carefully. Then:

zip -ry test.zip [0-9]* -x@excluded.files

gm3dmo
  • 10,057
  • 1
  • 42
  • 36
  • almost there; Running that command just zipped every numbered file in the directory + the correct folders, not just the folders - good enough for me though, thanks! – Professor Frink Oct 19 '10 at 22:32
0

Use find with -regex or the like to figure out which folder names are numeric, then use zip -@ to read the filtered list of filenames piped from find.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84