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 :)

  • What command line? You don't mention an OS, is it Windows, Linux, Mac, OS/2, GEM, CP/M, AIS, BeOS? – Chopper3 Oct 19 '10 at 21:21
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

  • 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.