Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

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
so

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

share|improve this answer
    
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 –  bdowning Feb 3 '12 at 2:53
add comment

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

share|improve this answer
add comment

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.

mountavfs
less ~/.avfs$PWD/file.tar\#/filename.log
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.