Jonathan Rioux
Jonathan Rioux

Reputation: 1096

Print a file content from a tar.gz archive

I would like to print a single file content from a tar.gz archive.

I know I can list the files from the archive like so:

$ tar -tf openjdk-17.0.2_linux-aarch64_bin.tar.gz
[...snip...]
jdk-17.0.2/lib/server/libjsig.so
jdk-17.0.2/lib/server/libjvm.so
jdk-17.0.2/lib/src.zip
jdk-17.0.2/lib/tzdb.dat
jdk-17.0.2/release      <---- print the content of this file (with 'cat' or 'more')

I want to print the content of the file jdk-17.0.2/release, preferably without extracting it if possible.

Upvotes: 0

Views: 749

Answers (2)

rabbit
rabbit

Reputation: 105

The following will extract that one file and write it to stdout

tar --extract -O --file=openjdk-17.0.2_linux-aarch64_bin.tar.gz jdk-17.0.2/release

I do not know how you print on your system but you can pipe the output to lp if that is set up.

tar --extract -O --file=openjdk-17.0.2_linux-aarch64_bin.tar.gz jdk-17.0.2/release | lp

Upvotes: 0

Chris
Chris

Reputation: 252

You can use vim instead, and then browse using your cursor:

vim openjdk-17.0.2_linux-aarch64_bin.tar.gz

Alternatively, have a look at this thread.

Upvotes: 1

Related Questions