Linux – Unzip individual files from multiple zip files and extract those individual files to home directory

linuxzip

I would like to unzip individual files. These files have a .txt extension. These files also live within multiple zipped files. Here is the command I'm trying to use.

unzip -jn /path/to/zipped/files/zipArchiveFile2011\*.zip /path/to/specific/individual/files/myfiles2011*.txt -d /path/to/home/directory/for/extract/

From my understanding, the -j option excludes directories and will extract only the txt files The -n option will not overwrite a file if it has already been extracted. I've also learned that the forward slash in /path/to/zipped/files/zipArchiveFile2011\*.zip is necessary to escape the wildcard (*) character.

Here is sample of error messages I'm coming accross:

Archive: /path/to/zipped/files/zipArchiveFile20110808.zip
caution: filename not matched: /path/to/specific/individual/files/myfiles20110807.txt
caution: filename not matched: /path/to/specific/individual/files/myfiles20110808.txt
Archive: /path/to/zipped/files/zipArchiveFile20110809.zip
caution: filename not matched: /path/to/specific/individual/files/myfiles20110810.txt
caution: filename not matched: /path/to/specific/individual/files/myfiles20110809.txt

I feel that I'm missing something very simple. I've tried using single quotes (') and double quotes (") around directory paths. But no luck.

Best Answer

For unzip command with range expression in filename, we need to escape both the range format and the wildcard in target filename, e.g. to unzip files with txt extension in order0710.zip, ... order0715.zip into folder txt_pool, we should issue command like this:

unzip -jn order071\[0-5].zip \*.txt -d txt_pool
Related Question