Tuesday, January 10, 2012

Editing config files in linux pico vs vim

As it appears Linux servers usually run without graphical shell and you only can arrange it using command prompt(terminal). I am trying Ubuntu 11 on my laptop and by the way u can start graphical shell with startx command if you need and to start cmd (terminal) in grahic mode press Ctl+Alt+T. In linux there are lots of config editing in files that you need to do an of course you need an editor. Out of the box I have pico. just type >sudo pico /etc/group


The sudo before pico means "Super User DO"  (RunAsAdmin).  If you omit sudo the file will open but in readonly mode. After editing press Ctl+X then Y(es) and [Enter].

By the way the file /etc/group defines groups in your system. To just list content use >less /etc/group

Keep in mind instead of Alt+F4 I use Ctl+Z to close active program in terminal screen.

Everything is great I can edit my groups file :).

But one problem is that if the file is long it is hard to edit it without syntax highlighting. So you can install vim editor using >sudo apt-get install vim-gnome

After installing vim you can use it instead of pico:>sudo vim /etc/group

now if you are following thease steps and tried editing file in vim you may be surprised, you cannot edit anything and even close it. And if you google for vim commands you can find quit command which is :q! . After reading a little I understood that by default vim is not in edit mode , it is in command mode , meaning everything you type is treated as a command to vim if you want to insert a line into vim just press [i] and you will see that you can edit the file. To go back to command mode press [ESCape]. Now if you want to close program write :q  in command mode (the command starting with : will appear in the bottom). If vim is unable to close you can force it using :q! which immediately quits vim without saving any changes. To save and close type :wq and :w filename to save using different filename(save as).

Thats all happy config editing :)

No comments:

Post a Comment