Sunday 28 August 2011

QuickBits-7: Convert .a file to .so file

.a files are just archive of .o object files. You need to just extract the files from the archive and package them as a shared object (.so).

ar -x myarchive.a


gcc -shared -Wl,-soname,mysharedlib.so *.o -o mysharedlib.so

Sunday 21 August 2011

QuickBits-6: Search and Kill Process

Many a times we need to find a process and kill it. The best way to Find a process is

Search
 pgrep -l [pattern] 

-l will list the name of the process or else only pid will be displayed. pgrep searches for the match in any part of the name including the arguments to the command.

Example:
 pgrep -l work


output
217 kworker/u:3
218 kworker/u:4
219 kworker/u:5
863 NetworkManager
900 ./a.out work

Search & Destroy
 pkill [pattern]

It will find and kill all the process that matches the Pattern.


Sunday 14 August 2011

QuickBits-5: Searching for previous commands

How to search and run the same command in bash ?

1. Up / down arrow keys [ good for previous few commands ]

2. Type ctrl+r and type any part of the command including its arguments. Bash will find and run it for you. Keep pressing ctrl+r until u find the right command.

Say you have run the following command sometime back

cd /myfolder/personal/secret/

you can search by typing ctrl+r and typing secret. Bash will find this command for you.