I have a bunch of text files/logs, which I'd like to pack into a gzipped tar archive, say:
cd /tmp
echo "My Content One" > aaa.log
echo "My Content OneA" >> aaa.log
echo "My Content Two" > bbb.log
echo "My Content TwoB" >> bbb.log
tar czvf test.tgz *.log
Now, if I open this with less test.tgz
, I get a listing of files same as tar tzvf test.tgz
would give me:
-rw-rw-r-- user/user 31 2017-10-29 03:10 aaa.log
-rw-rw-r-- user/user 31 2017-10-29 03:10 bbb.log
First, I found https://www.serverwatch.com/tutorials/article.php/3798511/Reading-Compressed-Files-With-less.htm, and tried setting up in my ~/.bashrc
:
alias tgzless='LESSOPEN="|tar --to-stdout -zxf %s" less'
Now I can do tgzless test.tgz
, and this prints the concatenated contents of all files:
My Content One
My Content OneA
My Content Two
My Content TwoB
... but unfortunately doesn't print the filenames, so I don't really know which part belongs where.
Then, I found How can i view the contents of a tar.gz file (filenames + filesize), and tried this command:
gzip -dc test.tgz | less
Now, this will print both a file heading, and the content of the file - unfortunately the file heading is binary and difficult to read - it looks something like this inside less
:
aaa.log^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@0000664^@0001750^@0001750^@00000000037^@131752
34246^@014636^@ 0^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ustar
^@user^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@user^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@My Content One
My Content OneA
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
...
... so it is hard to read (note that gzip -dc test.tgz | tar -tf - | less
gives just a listing of filenames, though less verbose one than tar tzvf
)
So can I set up an alias somehow using these standard commands, that would print all filename contents in a tar.gz archive, such that first the filename of the file is printed (preferably in tar tzvf
format, with username, permission and timestamp), and then its contents?