Alex Rivera | Logout

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

Asked 2009-07-10T23:47:29.043
89

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.

Edit
Report

1 Answer

4

you may want to use find(GNU) to find all your php,html etc files.then tar them up

find /path -type f \( -iname "*.php" -o -iname "*.css" -o -iname "*.js" -o -iname "*.ext" \) -exec tar -r --file=test.tar "{}" +;

after that you can zip it up

answered 2009-07-11T00:10:04.130

Your Answer