Unzip only a limited number of files in linux

I have a compressed file containing 10,000 compressed files. Is there a linux / bash script command to unzip only 1000 files? Please note that all compressed files have the same extension.

+4
source share
4 answers

You can use wildcards to select a subset of files. For instance.

  • Extract all contained files starting with b:

    unzip some.zip b *

  • Extract all contained files whose name ends in y:

    unzip some.zip * y.extension

, , unzip -l some.zip, , .

+1

:

unzip -l zipped_files.zip |head -1000 |cut -b 29-100 >list_of_1000_files_to_unzip.txt
, , 3 - ..

:

for files in `cat list_of_1000_files_to_unzip.txt `; do unzip zipped_files.zip $files;done
+1
unzip -Z1 test.zip | head -1000 | sed 's| |\\ |g' | xargs unzip test.zip
  • -Z1 provides a raw file list
  • sed expression encodes spaces (works everywhere, including MacOS)
+1
source

Some tips:

  • Run zip to display only files, redirect output to some file.
  • Truncate this file to get only 1000 lines.
  • Transfer file to zip to extract only specified files
0
source

Source: https://habr.com/ru/post/1530543/


All Articles