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







  -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


You need to exclude files in subfolders like this:

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



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


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


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


the archive name, of course


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

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

You must log in to answer this question.

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