Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

zip

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.

like image 995
willdanceforfun Avatar asked Jul 10 '09 23:07

willdanceforfun


People also ask

How do I zip certain files?

Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.

How do I zip an entire folder in Linux?

The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.

How do I zip a bunch of folders individually?

Steps to zip folders into multiple files:Open Winzip. From the WinZip file pane select the file you want to split. Next, click Add to Zip and make sure to select the Split option. Indicate where you want your zip files to be saved.

How do I exclude a zip file in Linux?

Exclude Multiple Files/Directories from Zip Archive You can define -x multiple times in a single zip command to exclude multiple files and directories from zip archive.


1 Answers

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' 
like image 156
Curtis Tasker Avatar answered Sep 21 '22 15:09

Curtis Tasker