Linux Unzip with exclusions from .txt file

2

I have an unzipping script on Linux.

It attempts to unzip with the command:

unzip file.zip 

This is obviously successful.

I now wish to exclude some files. The manual tells me of the -x option. I used that and it works also, but only for a single specified folder or file.

A method often used to exclude specific files from zipping programs is to pass in a .txt file with a single exclusion pattern per line.

Is this possible with Linux Unzip?

I have tried:

unzip file.zip -x excl_file.txt
unzip file.zip -x@excl_file.txt
unzip file.zip -x "excl_file.txt"

None of these seem to be the appropriate syntax.

Tom

Posted 2014-03-24T13:41:27.517

Reputation: 23

Answers

1

You can't pass a file containing list of exclusions to unzip, you rather pass multiple arguments to -x. You could use command substitution to pass the list as an argument to the -x option for unzip:

unzip file.zip -x $(<excl_file.txt)

devnull

Posted 2014-03-24T13:41:27.517

Reputation: 2 987

Surely you must mean $(<excl_file.txt)? – kojiro – 2014-03-24T14:01:27.587

@kojiro Indeed, the file isn't to be executed! Thanks. – devnull – 2014-03-24T14:02:12.890

I am not very familiar with command substitution, do you mean $(<excl_file.txt) ? edit: Oh, beaten to it! – None – 2014-03-24T14:06:51.380

@Tom $(<excl_txt) is another way of saying $(cat excl_txt) avoiding Useless Use of Cat. – devnull – 2014-03-24T14:09:12.107