Wednesday, January 16, 2013

Linux Util 3

1) To kill all processes of a process tree, say a bunch of  child processes spawned by a parent process (note that all the child processes have pids greater than that of parent's):

kill -9 -(ppid)

where ppid stands for parent pid. (just a negation symbol before the parent process id)

Another way to find the parent id (is same as process group id):

ps -eo "%p %r %c %a"
 
stackoverflow-page helped to solve this problem.

2) If you work by logging to your office machine (Linux server) from windows client machine using NoMachine (NX), and when you open lot of xterms, it is oftentimes confusing what each xterm window corresponding based just on the title of it. Just follow these steps to get new informative title (but this is active only for this session of your login)

unset PROMPT_COMMAND (assuming you have this env variable set in your .bashrc)
echo -ne "\033]0;title\007"
It is important to blindly follow the characters and their sequence in the echo command. Obviously, they mean something, but to keep the brevity, I am refraining from giving the explanation here.

3) If you want to do copy/paste operation in xterm, 

   a) highlight the text using mouse
   b) use middle button/scroll wheel of mouse to paste or
   c)  shift+insert to paste or when there is no middle button,or
   d) simultaneously click both mouse buttons to emulate middle-button click

Thanks to Ubuntu Forums for this help. 

4) All along I have been using pdftops - psselect - ps2pdf combination to select pages from a pdf document, but Today (Jan 23, 2013) I learnt about pdftk from
LinuxJournal to select pages from pdf document directly without converting to ps first. How nice!!

pdftk A=100p-inputfile.pdf cat A22-36 output outfile_p22-p36.pdf  

Input file is 100p-inputfile.pdf. Though the name sounds confusing, there is no need to prefix the name with 100p (100 pages).  It is just for this particular example. This command selects pages from 22 to 36 and creates an output file with just those pages.

5) April 17, 2013: Found this tip while wanting to put all docx files of submitted student homeworks in one directory to upload to google drive and open them there in order not to miss pictures or other openoffice incompatible things.
Thanks to Nixcraft I could do this and this is the first time I really found a way to use xargs command.

find . -name "*.docx" -print0 | xargs -0 -I file mv file onlydocs/


6)  To sync a local directory to a remote directory:

rsync -r -a -v -e "ssh -l yourname" local/directory/path remote.machine.address:remote/directory/path

You will be prompted to enter the password to the remote machine. If all else is correct, this should sync the files. Thanks to Nixcraft for this tip.