Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzip only limited number of files in linux

Tags:

unzip

I have a zipped file containing 10,000 compressed files. Is there a Linux command/bash script to unzip only 1,000 files ? Note that all compressed files have same extension.

like image 596
rocx Avatar asked Mar 07 '14 06:03

rocx


2 Answers

unzip -Z1 test.zip | head -1000 | sed 's| |\\ |g' | xargs unzip test.zip
  • -Z1 provides a raw list of files
  • sed expression encodes spaces (works everywhere, including MacOS)
like image 107
chadwackerman Avatar answered Oct 04 '22 06:10

chadwackerman


You can use wildcards to select a subset of files. E.g.

  • Extract all contained files beginning with b:

    unzip some.zip b*

  • Extract all contained files whose name ends with y:

    unzip some.zip *y.extension

You can either select a wildcard pattern that is close enough, or examine the output of unzip -l some.zip closely to determine a pattern or set of patterns that will get you exactly the right number.

like image 27
Slartibartfast Avatar answered Oct 04 '22 06:10

Slartibartfast