tar -tvf file.tar contains log files. Is there anyway to do something like this

tar -tvf file.tar | head -1 | awk '{print $NF}' | xargs less {}

This would give file not found, but is there a way?


If you don't use the v switch with tar, you'll just get a list of file names, not an ls -l listing.
I'm assuming you only want to look at the first file from the head -1

tar xfO file.tar `tar tf file.tar | head -1` |less

Will work to view the first file

That last switch is an uppercase 'O' Oh not 0
-O, --to-stdout extracts files to standard output

If you want to view them all at once

tar xfO file.tar | less

But you'll lose the exact name of the log file you're viewing

  • It is saying tar:Options `[0-7][lmh]' not supported by this tar. I might not have the right tar version. vim is working for me, but that will result in a massive head-ache for memory I suppose. – user14039 Feb 2 '12 at 23:45
  • my bad it is capital o, it is working. – user14039 Feb 2 '12 at 23:49
  • Showing O vs. 0 properly has been discussed on meta, sorry for not making that clear – bsd Feb 3 '12 at 2:53

You can open a tar in vim, browse its file structure, and read the files. (I'm sure emacs can do it too).


AVFS is a virtual filesystem (based on FUSE) that allows you to see inside archives as if they were directories.

Run mountavfs once and for all (it'll persist until the next reboot; you should put it in your ~/.profile). This creates a view of the whole filesystem rooted at ~/.avfs. Inside this view, every archive has an associated directory whose name has an extra # at the end. This directory contains the contents of the archive.

less ~/.avfs$PWD/file.tar\#/filename.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy