Showing posts with label xterm. Show all posts
Showing posts with label xterm. Show all posts

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.

Friday, January 6, 2012

Linux Util 2

1) You can try to place a tab between the quotes if you first press "<CTR> v" then the "<TAB>" key:


cut -f1 -d'<ctrl>v <tab>' filename

This way even <tab> character can also made as delimiter in shell scripting.

2) If you have a file where first column is list of years with author names against each year, to find the count of papers in each year:

cut -f1 -d' ' fname |uniq -c


3) To find all empty lines in the standard input:
grep ^$  or  grep -v .   


4) Hmm, long live blogging: I was looking for grep command to search for a text recursively from a given directory and this blogger helped:

http://www.geekality.net/2011/04/12/unix-recursive-search-for-text-in-files/

grep -rl "your_text"

5 ) To redirect the output of time (real, sys, usr) command onto redirect_file, instead of console.

(time your_command your_args) 2>> redirect_file

6) To search for a file's contents in another file:

grep -f searchfile tobesearchedfile -n --color=auto

Can remove the color flag. Got this color tip from Nixcraft

7) To list only the duplicate lines of a file:

uniq -d filename

8) To unzip a file that is only compressed with bz2 use

bunzip2 filename.bz2

9) To unzip things thar are compressed with .tar.bz2 use

tar -xvjpf filename.tar.bz2

I got the tips 8 and 9 from linuxquestions.org

10) Many a times, to know if the server I am working in is serving a lot of users, I type w in the shell prompt. This is useful if you are going to run a resource-greedy process. Now, if you are interested to write/talk to them, you may want to know their full name. The following command helps to get their full names from an administrative database:

getent passwd "jey"|cut -d':' -f5

If you are curious, an encouraging fact is man page of getent is small :) !!
Happy linuxing!!

11) Wow, after about 5 months (it's Jan 8, 2013 today), I am glad to be updating my blog. Yup, it also means I have failed to keep track of my new findings in web in this database. Anyways, the following tip was something very important to me because I realized I am spending too much time 'Alt+tab'ing to find the window I want to work in while working from home, logging to my office machine (essentially all are xterms).

To change the title of the xterm window to indicate something useful (in this example, your_string):
unset PROMPT_COMMAND
echo -ne "\033]0;your_string\007"

I had to call unset first because by default in my .bashrc file, PROMPT_COMMAND stores the username, machine and current working directory. It is important to observe the combination of characters around "your_string" and follow them strictly.