how do I zip a whole folder tree in unix, but only certain files?

willdanceforfun picture willdanceforfun · Jul 11, 2009 · Viewed 49k times · Source

I've been stuck on a little unix command line problem.

I have a website folder (4gb) I need to grab a copy of, but just the .php, .html, .js and .css files (which is only a couple hundred kb).

I'm thinking ideally, there is a way to zip or tar a whole folder but only grabbing certain file extensions, while retaining subfolder structures. Is this possible and if so, how?

I did try doing a whole zip, then going through and excluding certain files but it seemed a bit excessive.

I'm kinda new to unix.

Any ideas would be greatly appreciated.

Answer

Curtis Tasker picture Curtis Tasker · Jul 11, 2009

Switch into the website folder, then run

zip -R foo '*.php' '*.html' '*.js' '*.css' 

You can also run this from outside the website folder:

zip -r foo website_folder -i '*.php' '*.html' '*.js' '*.css'