Ubuntu: Close specific pdf open in Document Viewer


I have opened abc.pdf in Document Viewer 3.18.2. I am writing bash script to close the specific document opened in Document Viewer. Any idea ?


The command

ps -Af|head  

displays the a header and the first 9 processes. This helps you identify which column that contains the process ID (PID).

The command

ps -Af|grep evince | grep abc.pdf  

displays processes where evince is running files, that contain adc.pdf in the file name. Normally it will be only one such process. And you kill it like you did manually, but with that command in the script.

You can create a variable that contains the PID, and use it for the kill command. In my Lubuntu 16.04.1 LTS system the second column contains the PID. The following two command lines should do the job from a shellscript file.

pid=$(ps -Af|grep evince | grep abc.pdf| tr -s ' ' ' '|cut -d ' ' -f 2)  kill $pid  

You may have to modify the first of these lines, so that it picks the correct column or 'field' with the option -f at the end. (And you may have to modify the file name, if it is not always abc.pdf.)

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