Suppose I open a file (pdf) with a command line in Ubuntu by running

xdg-open abc.pdf

The pdf is shown in a pdf reader which is set as default.

Now how can I close this pdf viewer from the command line in Ubuntu?

  • 1
    try pkill <pdf_viewer_process_name> – George Udosen Dec 28 '18 at 13:54
  • Just beware that this will close ALL pdfs opened with xdg-open - which is fine as long as that's your intent. – Eric Mintz Dec 28 '18 at 14:02
  • Not from command line, but you can press Alt+F4 to close a window (or sometimes Ctrl+Q or Ctrl+W). That might be more convenient in the end. – wjandrea Dec 28 '18 at 14:13
  • xdotool might be useful. Maybe you could use it to find which window has that PDF open, and close it. – wjandrea Dec 28 '18 at 14:16
  • An -almost- dupe of this one askubuntu.com/questions/616738/… but you could of course get the window- id by just wmctrl, make your pick, then wmctrl -ic <window_id> – Jacob Vlijm Dec 28 '18 at 18:20
fuser -k -TERM FILE

Replace FILE with the name of the file in question.

Check the link below for a fuller description (and be aware this is a powerful/ dangerous command)

Source: Is there something like an “xdg-close” - opposite of xdg-open? on Unix & Linux

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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