Ubuntu: Open pdf in tar.gz without extracting



Question:

I have a tar.gz which have pdfs in it I want to open a specific pdf without extracting it Is this possible using terminal through some command (I know we can do it using GUI but I want to use terminal)


Solution:1

To list (not-open) files in archive without extracting, run following command:

tar -tf myarchive.tar.gz  

To extract and open directly run following command:

tar -xzf myarchive.tar.gz && evince *.pdf  

For quick process: (extacted in /tmp/mypdf and then removed)

mkdir /tmp/mypdf && tar -xzf myarchive.tar.gz -C /tmp/mypdf && cd /tmp/mypdf && evince *.pdf && cd .. && rm -r mypdf  

Where myarchive.tar.gz is your sample archive name.


For extracting specific file,

mkdir /tmp/mypdf && tar -xzf myarchive.tar.gz -C /tmp/mypdf "<file.pdf>" && cd /tmp/mypdf && evince *.pdf && cd .. && rm -r mypdf  

where "<file.pdf>" is file-name of that specific file you want to extract & open.

Hope it is helpful. For advance function scripted command is useful by running script for specific purpose.


Solution:2

To do this in a single command line, you need a pdf viewer which can handle input from a pipe. The only viewer with this option I know is ImageMagicks's display. It is not very comfortable (larger files may take a while), but may be it is convenient for your purpose.

tar xOfz <archive> <path/to/file/in/archive> | display  

(Larger pdf files may take a while.)


Solution:3

Opening without extracting is not possible. GUI applications are extracting the files temporarily before opening them...

If you have one tar.gz file containing PDF files, and you wish to extract one or more files using command line, you can use:

tar -xzf MyArchive.tar.gz MyPDF5.pdf    tar -xzf MyArchive.tar.gz MyPDF6.pdf MyPDF3.pdf    tar -xzf MyArchive.tar.gz "My PDF 128.pdf"  

You can also extract one file from a folder in the archive (the directory structure will be kept):

tar -xzf MyArchive.tar.gz "My Archive Folder/My Other PDF.pdf"  

If you don't wish to keep the directory structure, you can use --strip-components followed by the level of the subfolder:

tar -xzf MyArchive.tar.gz "My Archive Folder/My Other PDF.pdf" --strip-components 1    tar -xzf MyArchive.tar.gz "e-Books/Favorites/Ubuntu Linux/My PDF about Ubuntu.pdf" --strip-components 3  

Please note that your archive file name must also be double-quoted if it contains spaces.

In the examples above, I'm supposing that you are in the folder containing the archive file and that you wish to extract there.

Before using tar command, you should use "cd" command to go to the folder in which you wish to extract the files. If the archive is located in another folder, simply put its absolute full path ["/home/myusername/Desktop/My Folder/My Other Archive.tar.gz"] (using a relative path may also be useful in some cases).

P.S.: If it was a simple text file (txt), "-O" parameter at the end of the command might have been what you were searching for, but since it is a PDF one, it is not very useful... According to TAq answer, "display" from ImageMagick is able to handle that PDF output the way you wish with a pipe.

tar -xzf MyArchive.tar.gz "My PDF 128.pdf" -O | display  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »