unixzip

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


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.


Solution

  • Switch into the website folder, then run

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

    You can also run this from outside the website folder:

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