Friday, February 4, 2011

vim comment lines

In linux, while editing configuration files, we always used # sign for comments. How do we do it to multiple lines in vi easily?

Steps:

1. Edit the files using vi
$ vi files.conf

2. set line number in vi (for us to easily determine what is the line number that we want to edit)
:se nu

3. replace start of lines with # (for example, put # sign in front of line 2 to line 5). The meaning of below command is for line 2 - 5, subtitute (s) start of line (^) with # sign, and press enter
:2,5s/^/#/
<enter>

4. It is done. Save your file (w) and quit (q)
:wq

Thursday, December 2, 2010

yum plugin to remove dependencies

You can remove dependencies using yum-plugin-remove-with-leaves plug-in.

To install:

# yum install yum-plugin-remove-with-leaves

To use:
# yum remove --remove-leaves <package-name>

That's all folks :)

Friday, November 26, 2010

Using markers in vi/vim

This feature is useful if for example we want to delete a few lines or characters but we are too lazy to count the lines or characters to use dd or dw command. We can set up to 26 marker using lowercase a-z as the marker's name. The main usage of marker is to mark any location in file.

How to use (we put 'a' as the marker's name):

ma - mark current cursor position as marker named 'a'
`a (backquote a) - move to character marked as 'a'
'a (quote a) - move to first non blank character (line) containing marker 'a'
`` (backquote backquote) - move to last operated marker or toggles with last cursor position, if no marker is set, cursor moves to beginning of file (BOF)
'' (quote quote) - move to beginning og line (BOL) operated marker or toggles with BOL of last cursor position, if no marker is set, cursor moves to BOF

Example on using marker:

If you want to indent 5 lines starting from current line: majjjjj>'a
If you want to delete five words using marker: mawwwwwmb`ad`b

That's all friends :)

Saturday, November 13, 2010

Edit main menu in fedora

Starting from fedora 12, I found out that I cannot edit my main menu anymore. This is kind of frustrating since I installed many custom applications, and I would like it to be easily accessible from the main menu. After searching around, i found out that one package is not included in fedora 12 livecd. The package is called alacarte.

$ rpm -qi alacarte
Name : alacarte Relocations: (not relocatable)
Version : 0.12.4 Vendor: Fedora Project
Release : 1.fc12 Build Date: Tue 22 Sep 2009 08:41:26 AM MYT
Install Date: Sat 13 Nov 2010 07:17:32 AM MYT Build Host: xenbuilder4.fedora.phx.redhat.com
Group : Applications/System Source RPM: alacarte-0.12.4-1.fc12.src.rpm
Size : 367423 License: LGPLv2+
Signature : RSA/8, Thu 01 Oct 2009 03:42:28 AM MYT, Key ID 9d1cc34857bbccba
Packager : Fedora Project
URL : http://www.gnome.org
Summary : Menu editor for the GNOME desktop
Description :
Alacarte is a graphical menu editor that lets you edit, add, and delete
menu entries. It follows the freedesktop.org menu specification and
should work with any desktop environment that uses this specification.

So, just install the alacarte package using yum, and select "System -> Preferences -> Main Menu", and you can now edit your main menu.
# yum install alacarte -y
That's all folks

Tuesday, October 26, 2010

Xen's domU always depend on dom0's time and date

By default, the time and date in domU is following dom0. To reset that, below are just what you have to do to decouple the domU's date from dom0

On dom0:

Append xen.independent_wallclock=1 to /etc/sysctl.conf

# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf
Activate the change
# sysctl -p
Append extra="clocksource=jiffies" to the domU's configuration file.
# echo "extra=\"clocksource=jiffies\"" >> /etc/xen/<domU's name>.cfg 


On domU:

Append xen.independent_wallclock=1
# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf 
Activate the change
# sysctl -p 
Append jiffies to /sys/devices/system/clocksource/clocksource0/current_clocksource
# echo "jiffies" >> /sys/devices/system/clocksource/clocksource0/current_clocksource

Now you can set your domU's date using "date" command or "ntpdate" to get update from ntp servers.

That's all folks