All commands tested on Mac OS Monterey / Jan 05, 2022

How to extract files of a specific filetype from a tar archive

Extract *.png files from the files.tar archive.

You can use this short tar command.

              
                  tar -xvf files.tar --include '*.png'
              
          

Or this more verbose tar command.

              
                  tar --extract --verbose --file files.tar --include '*.png'
              
          

Note: The required directories will be extracted also.


Options explained

  1. -x or --extract tells tar to extract an existing archive
  2. v or --verbosetells tar to produce verbose output
  3. f or --filetells tar that the next parameter will be the tar file to create, extract, append to, list, etc.
  4. --include tells tar to process files or directories that match the specified pattern

More commands for extracting from tar archives