Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I constantly have many PDF files open. These are usually downloaded using chrome and immediately opened using evince.

I sometimes want to persist the state of all my open PDF files, so I could re-open the same group of documents at a later time.

This mostly happens when I need to reboot and what to have the same set of documents re-opened, but sometimes I just want to keep a list of open documents for later.

Is there a way to get the names of all open pdf files, from evince or any other program? or at least, is there a way of asking evince to re-open the same set of documents after a reboot?

share|improve this question
up vote 2 down vote accepted

Under the assumption that the PDFs you are viewing have the extension .pdf, the following could work to get you a list of open PDFs:

$ lsof | grep ".pdf$"

If you only ever use Evince, see Gilles' similar answer. On my machine (with a few pdfs open) displayed output as follows

evince    6267     myuser   14u      REG    252,0   363755    7077955 /tmp/SM.pdf

To just get the filenames, we can use awk:

$ lsof | grep ".pdf$" | awk '{print $9}'

or even better,

$ lsof | awk '/.pdf$/ {print $9}'

We can save these results in a file:

$ lsof | awk '/.pdf$/ {print $9}' > openpdfs

And later, to restore them:

$ xargs -a openpdfs evince

To make this happen automatically, you can use whatever mechanisms your desktop environment provides to run the "save" command on exit and the "open" command on login. A bit more robustness can be added by ensuring that the pdf's returned by lsof are being opened by your user. One advantage of this method is that it should work for any pdf viewer that takes command-line arguments. One disadvantage is that it depends on file names; however, with a bit of poking, the requirement of knowing the filename extension could probably also be removed.

share|improve this answer
thank you, lsof is exactly what I was looking for. – Yoav Jan 11 '11 at 15:03

lsof lists the files open by a process. Evince does keep the files open. If you're the only user using evince, under Linux, here's how to see what files it's using:

lsof -p $(pidof evince)

To automate this, you'll want to keep only the open regular files of the evince process. Here's a script that outputs the file names.

lsof -n -d0-9999 -Fpctn |  # parseable output, pid/command/type/name, only open files
sed 's/^p/\np/' |  # split each process into a paragraph
awk -vRS= '/\ncevince\n/ {print}' |  # retain only paragraph(s) with command="evince"
sed 's/^t/\nt/' |  # split each file into a paragraph
awk -vRS= '/^tREG\n/ {print substr($0, 7);}'  # retain only regular files
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.