Tuesday, December 18, 2012

Searching in vim with ignorecase on

This is for searching any string in vi or vim, regardless of the case. All you need to do is to press

/\c
while you are in vim followed by your pattern to start this ignore case search. For example, if you  have a list like below:

Miu
MIu
MiU
mIU

and search in vim using
/\cmiu
, vi will list every line as the search output, even though the cases are different. try it :)


Thursday, November 22, 2012

Listing all available version of a package using yum

Sometimes you want to see what version of a package is available on a repo, below is how you do it:

[humans@earth]$ sudo yum list subversion --showduplicates

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: dist1.800hosting.com

 * epel: mirror.steadfast.net

 * extras: centos.mirror.lstn.net

 * rpmforge: mirror.us.leaseweb.net

 * updates: mirror.raystedman.net

Installed Packages

subversion.x86_64                                                         1.6.11-10.el5_8                                                           installed

Available Packages

subversion.i386                                                           1.6.11-7.el5_6.4                                                          base    

subversion.x86_64                                                         1.6.11-7.el5_6.4                                                          base    

subversion.i386                                                           1.6.11-10.el5_8                                                           updates 

subversion.x86_64                                                         1.6.11-10.el5_8                                                           updates

You make that happened by using --showduplicates flag, which will show all version available for subversion, in this case :)


Thursday, November 1, 2012

Using & as replacement for matched string in sed

This is useful, if you need to add some modification to your searched string in sed, but you are using regex and you do not know what the output would be. Please see below example:

$ echo "123 123 abc abc" | sed 's/[0-9]*/(&)/'
(123) 123 abc abc

In this example, your requirement is to put parentheses around your matched/searched string. So I put '&' as the replacement for the searched string, which is any series of number between 0 to 9, and put parentheses around it.

Done :)


Tuesday, June 12, 2012

sudo: unable to execute /bin/rm: Success

I found a weird error message when I tried to delete some files in my linux box today. The command I used was

sudo rm -rf *.js
to delete some .js files, and I got an error message:
sudo: unable to execute /bin/rm: Success
After googling around, I found this wonderful site, and the solution is to use find coupled with -exec flag rather than rm:
sudo find . -iname '*.js' -exec rm {} \;
The problem is, according to the site, was caused by buffer overflow when expanding the *. 
The single quote that we used in the find command will prevent it from expanding and causing overflow.

So, that's all folks. 

Thursday, May 17, 2012

Show memory map of a process

How to show memory map of a process? or how to check how much memory a process is consuming?
Use pmap.

How to use pmap:

  1. get a pid of a process you are interested in checking, in this example apache:
    [mainuser@serverone ~]$ ps -eaf | grep http 
    root      1759  4493  0 04:02 ?        00:00:00 /usr/sbin/httpd
    apache    1760  4493  0 04:02 ?        00:00:25 /usr/sbin/httpd
    apache    1761  4493  0 04:02 ?        00:00:23 /usr/sbin/httpd
    apache    1762  4493  0 04:02 ?        00:00:21 /usr/sbin/httpd
    apache    1763  4493  0 04:02 ?        00:00:18 /usr/sbin/httpd


  2. run the pmap command against the PID number:
    [mainuser@serverone ~]$ sudo pmap 1760 | tail 
    97406000     28K r--s-  /usr/lib/gconv/gconv-modules.cache
    97463000     16K rw---    [ anon ]
    97467000 524288K rw-s-  /tmp/apc.tE1RRo (deleted)
    b7467000  11096K r----  /usr/local/zend/lib/libicudata.so.38
    b7f3d000      4K rw---  /usr/local/zend/lib/libicudata.so.38
    b7f3e000     64K rw-s-  /dev/zero (deleted)
    b7f4e000    504K rw-s-  /dev/zero (deleted)
    b7fcc000     32K rw---    [ anon ]
    bfd74000    144K rwx--    [ stack ]
    total  2742152K
     
  3. The process, which is apache is consuming about 2.7GB of memory
That's all folks :)