Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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