1

I have a tar file. That's what its structure looks like:

-images.tar.gz

  -folder_0_image_1.jpg
  -folder_0_image_2.jpg
  -folder_0_image_3.png
  -...

  -folder_1

      -folder_1_image_1.jpg
      -folder_1_image_2.jpg
      -...

  -folder_2

      -folder_2_image_1.jpg
      -folder_2_image_2.jpg
      -...

  -folder_x ...

How do I extract all the files from the root directory that have the .jpg extension?

(I'd like to extract these files: folder_0_image_1.jpg, folder_0_image_2.jpg ...)

1 Answer 1

3

You need to exclude files in subfolders like this:

tar --wildcards --exclude='*/*' -xvzf images.tar.gz '*.jpg'

Explanation:

 --wildcards

means we specify files to extract by a wildcard, i.e. *.jpg - specified later

--exclude='*/*'

an option to exclude (from being selected for extraction) all entries with a / in them - i.e. all files in subfolders

-xvzf

eXtract, Verbose output, gunZip decompress first, archive from a File

images.tar.gz

the archive name, of course

'*.jpg'

filename pattern - we promised tar one, here it is - everything that ends in .jpg.

2
  • Thank you for your detailed answer.
    – fff
    Aug 14, 2019 at 20:27
  • @fff You're welcome :-)
    – Ned64
    Aug 14, 2019 at 22:23

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .