Linux – Look at the tar log contents without extracting them

linuxtar

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?

Best Answer

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