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

How to find the location of a file in tar archive

find the location of my-file.txt in the files.tar tar archive.

You can use this short tar command.

              
                  tar -tvf files.tar | grep myfile.txt
              
          

Or this more verbose tar command.

              
                  tar --list --verbose --file files.tar | grep myfile.txt
              
          

The commands above will list the files inside the files.tar tar archive that match my-file.txt.

If you don't recall the exact name of the file you need to find, you can grep for part of the filename Ie. grep my-file.


Options explained

  1. -t or --list 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.

More commands to list the contents of tar archives