Read concatenated output of tgz archive (with plain text files), with filenames, without unpacking in bash?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
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?
tar less gzip
add a comment |Â
up vote
2
down vote
favorite
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?
tar less gzip
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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?
tar less gzip
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?
tar less gzip
edited Nov 19 '17 at 14:30
Jeff Schaller
32.1k849109
32.1k849109
asked Oct 29 '17 at 2:23
sdaau
2,54763047
2,54763047
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Assuming youâÂÂre using GNU tar
, create a file named tarcat
on your path with the following contents:
#!/bin/sh
# Permissions user/group size date time name
printf "%s %s/%s %7d %s %sn" "$TAR_MODE" "$TAR_UNAME" "$TAR_GNAME" "$TAR_SIZE" "$(date -d @$TAR_ATIME)" "$TAR_FILENAME"
exec cat
Then run tar x --to-command=tarcat -f test.tgz | less
:
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 aaa.log
My Content One
My Content OneA
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 bbb.log
My Content Two
My Content TwoB
Decoding the octal file mode and adapting the date/time output is left as an exercise for the reader.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Assuming youâÂÂre using GNU tar
, create a file named tarcat
on your path with the following contents:
#!/bin/sh
# Permissions user/group size date time name
printf "%s %s/%s %7d %s %sn" "$TAR_MODE" "$TAR_UNAME" "$TAR_GNAME" "$TAR_SIZE" "$(date -d @$TAR_ATIME)" "$TAR_FILENAME"
exec cat
Then run tar x --to-command=tarcat -f test.tgz | less
:
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 aaa.log
My Content One
My Content OneA
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 bbb.log
My Content Two
My Content TwoB
Decoding the octal file mode and adapting the date/time output is left as an exercise for the reader.
add a comment |Â
up vote
2
down vote
Assuming youâÂÂre using GNU tar
, create a file named tarcat
on your path with the following contents:
#!/bin/sh
# Permissions user/group size date time name
printf "%s %s/%s %7d %s %sn" "$TAR_MODE" "$TAR_UNAME" "$TAR_GNAME" "$TAR_SIZE" "$(date -d @$TAR_ATIME)" "$TAR_FILENAME"
exec cat
Then run tar x --to-command=tarcat -f test.tgz | less
:
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 aaa.log
My Content One
My Content OneA
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 bbb.log
My Content Two
My Content TwoB
Decoding the octal file mode and adapting the date/time output is left as an exercise for the reader.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Assuming youâÂÂre using GNU tar
, create a file named tarcat
on your path with the following contents:
#!/bin/sh
# Permissions user/group size date time name
printf "%s %s/%s %7d %s %sn" "$TAR_MODE" "$TAR_UNAME" "$TAR_GNAME" "$TAR_SIZE" "$(date -d @$TAR_ATIME)" "$TAR_FILENAME"
exec cat
Then run tar x --to-command=tarcat -f test.tgz | less
:
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 aaa.log
My Content One
My Content OneA
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 bbb.log
My Content Two
My Content TwoB
Decoding the octal file mode and adapting the date/time output is left as an exercise for the reader.
Assuming youâÂÂre using GNU tar
, create a file named tarcat
on your path with the following contents:
#!/bin/sh
# Permissions user/group size date time name
printf "%s %s/%s %7d %s %sn" "$TAR_MODE" "$TAR_UNAME" "$TAR_GNAME" "$TAR_SIZE" "$(date -d @$TAR_ATIME)" "$TAR_FILENAME"
exec cat
Then run tar x --to-command=tarcat -f test.tgz | less
:
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 aaa.log
My Content One
My Content OneA
0664 user/user 31 Sun 29 Oct 03:10:00 UTC 2017 bbb.log
My Content Two
My Content TwoB
Decoding the octal file mode and adapting the date/time output is left as an exercise for the reader.
answered Oct 29 '17 at 13:41
Stephen Kitt
144k22312377
144k22312377
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401145%2fread-concatenated-output-of-tgz-archive-with-plain-text-files-with-filenames%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password