Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zip files with exclude list in linux/unix

Tags:

file

zip

I have a list of files that I want to zip but I also have a list to exclude files and do not want them to be included in the zip archive.

so I have created a exclude.lst file and it has absolute path and filenames in it.

sample exclude file

/home/logs/apache/access.log
/home/logs/tomcat/catalina.out

but after using the below command, the zip command is not excluding the files rather archiving them.

zip archives.2012.zip /home/logs/ [email protected]

how can I overcome this ? and is there any other way to archive files by excluding the above files.

like image 625
CBR Avatar asked Jun 15 '12 20:06

CBR


People also ask

How exclude files from zip Linux?

You can define -x multiple times in a single zip command to exclude multiple files and directories from zip archive.

How do I zip a list of files in UNIX?

Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.

How do I list the contents of ZIP files in Linux?

To list/view the contents of a compressed file on a Linux host without uncompressing it (and where GZIP is installed), use the "zcat" command.

How do I zip multiple folders into a zip file in Linux?

Select the “Files” option : your file explorer should start automatically. Now that you are in your file explorer, select multiple folders by holding the “Control” key and left-clicking on all the folders to be zipped. When you are done, right-click and select the “Compress” option.


1 Answers

Instead of creating exclude.lst file, I'm assigning all the exclude files to a variable and passing those to the -x option in the zip.

For example

do_not_archive=/home/logs/apache/access.log /home/logs/tomcat/catalina.out

Then use zip as shown below

zip archives.2012.zip /home/logs/ -x $do_not_archive
like image 63
CBR Avatar answered Sep 20 '22 17:09

CBR