Monday, February 11, 2013

Clear off swap

Today I have an issue where my swap is almost full. To check your swap usage:

$ free -m

                    total       used       free     shared    buffers     cached

Mem:          1024        157        866          0         11         48

-/+ buffers/cache:         97        926

Swap:          127         95         32

where -m is for the value to be listed in megabytes.

To clear the swap off, please use below commands (please run as root, or sudo):

# sync && /sbin/sysctl vm.drop_caches=3 && swapoff -a && swapon -a 


where sync is to force changed blocks to disk and update the super block; sysctl vm.drop_caches=3 is to free pagecache, dentries and inodes; swapoff is to turn off swap and swapon is to turn swap back on, obviously :)

p.s. Thanks to linuxnetadmin and linuxinsight for the tips.

And you will get free swap after that:

$ free -m

                    total       used       free     shared    buffers     cached

Mem:          1024        157        866          0         11         48

-/+ buffers/cache:         97        926

Swap:          127         0         127
 
 
That's all folks.

Friday, February 1, 2013

ldapvi - ldap client using text editor

Today I stumbled upon a good tool in managing ldap, which is ldapvi. The reason this tool champs over my previous ldap management tool, which is phpldapadmin, is, it is based on text editor, and can be used in terminal ~ cool :)

To install this tool, all you need is to use your package manager, in my case, yum:

$ sudo yum install ldapvi

Once you have finished installing, launch it with your username and ldap server:

$ sudo ldapvi --user cn=admin,ou=people,dc=local,dc=lan  --host ldap.local.lan

For first time use, you need to set your preferred text editor. Once logged in, you can change the ldap record as if you are working on a very long text file. Once you are done, save like how you normally save a text file, ldapvi will ask for confirmation, and you are done.


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 :)