Sunday, July 5, 2009

Learning (from) bash history

The Bourne Again Shell (bash) is the default shell in almost all Linux distributions. The bash shell has a history feature which can make life easier for any serious Linux user.
Open a shell and try the following .

$echo $HISTFILE $HISTSIZE $HISTFILESIZE
/home/fermi/.bash_history 500 500

The HISTFILE environment variable points to the name of the file where bash history is stored. When bash exits, history in memory is written back to the .bash_history file. The number of commands held in history during a bash session is set by $HISTSIZE, while the number of commands actually stored in the history file is set by $HISTFILESIZE.

You can use history command to list the entire command line history.
$history
You can list the last n entries in the history as below. (n=5)

$history 5
424 man fc
425 echo $HISTFILE $HISTSIZE $HISTFILESIZE
426 history
427 history 10
428 history 5

You can use up arrow and down arrow keys to move around the history buffer.Once a command is displayed, you can use the keyboard to edit the current command like any other command: left arrow, right arrow, Delete, Backspace, and so on.

There are some other tricks you can use .

~$ !! run the previous command
~$ !427 run command numbered 427 from history
~$ !423 *.jpg append *.jpg to command 423
~$ !ls run previous command starting with ls

You can search command history for a specific string by pressing Crtl together with r

$ <Ctrl+r> ( You will not see this)
reverse-i-search)`':

You can type in the string to be searched after the colon and press enter.
You can press Ctrl+r repeatedly to search backwards through your history list for a specific occurrence of the string.

There is another way of editing the history using fc command. Try this

$fc -e vim 427

This will open command 427 in vim and you can edit it and save it back to history. RTFM fc for details.

Saturday, July 4, 2009

Watching movies with smplayer




The mplayer project is one of the best movie players for both windows and linux. Mplayer is basically a console based player. There are several projects on the internet providing GUI front ends to mplayer.
smplayer is one of the best front ends that you can download. Both source and binary releases of smplayer are available on sourceforge.

For installation on ubuntu 9.04 you can try the following steps. The mplayer bundled with jaunty is slightly outdated. You can update mplayer to a more recent version and install smplayer front end following the steps below.

Step 1
Add the following lines to /etc/sources.list

  deb http://ppa.launchpad.net/awn-testing/ubuntu jaunty main
deb http://ppa.launchpad.net/rvm/mplayer/ubuntu jaunty main


Step 2
Open a terminal and add the apt key of the PPA

 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 12345678
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 03E02400

Step 3
Update
 sudo apt-get update

Step 4
Install and enjoy.
 sudo apt-get install mplayer
sudo apt-get install smplayer

A windows version of smplayer is also available on the website.

Installing midori on ubuntu Jaunty




Midori is a light weight browser developed as a part of Xface desktop environment. You can download the source code of midori from here. It uses webkit rendering engine and gtk2. This how to will show the installation of midori on Ubuntu 9.04 .

Step 1
Add the follwoing repositories to /etc/sources.list
deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
deb http://ppa.launchpad.net/midori/ppa/ubuntu jaunty main

Step 2

Import the keys of the above PPAs

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2D9A3C5B
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A69241F1


Step 3
Update the apt database
sudo apt-get update

Step 4

Install midori
sudo apt-get install midori

Enjoy the browser. Don't forget to report bugs as the software is under heavy development.

Sunday, June 28, 2009

Using ssh to access GUI program on a remote machine

Suppose you have two machines A and B . Let the ip addresses for A and B be a.a.a.a and b.b.b.b respectively. We will try to run gedit on B and get the graphical output on A. I am assuming both machies are ubuntu 9.04 Jaunty. This will work on other flavours of Linux too.

Install openssh server on machine B.
$ sudo apt-get install openssh-server

In Ubuntu ssh server will be started automatically. If not start it

$ sudo /etc/init.d/sshd start

Now you can connect to B from A

$ssh username@b.b.b.b

username will be user of system B.

When you do this for the first time , you may be asked to type yes/no to add the finger print of the remote machine. Now enter the password and you are done.

You can execute normal shell commands on machine B now.


$ssh -X username@b.b.b.b

will also allow you to take GUI control.

Try running gedit on the remote machine. The GUI will come on your local machine.

Friday, June 26, 2009

enter password for default keyring to unlock

Today I was fiddling around my Ubuntu ( jaunty ) desktop . I installed twitux , a twitter client and was happy with it. I switched off the machine and went for lunch. When I came back, twitux started asking this.

"enter password for default keyring to unlock
The application 'Twittux
wants access to the default keyring but it is locked"

I tried out my default login password. But could not start twitux.

I searched on net and finally arrived at a solution.

Here it is.
$ cd ~/.gnome2/keyrings
$ rm deault.keyring
That fixed my problem. The next time I started twitux, it asked me to setup a new password for the key ring.

Setting up static IP in ubuntu 9.04 Jaunty

The network manager shipped with ubuntu 9.04 is not working properly when you try to setup a static ip.
Here is the solution.

$ sudo apt-get remove network-manager-gnome

The edit
/etc/network/interfaces
and set the interfaces manually

Here is my interfaces file.

auto lo
auto eth1
auto eth0

iface lo inet loopback
iface eth1 inet dhcp
iface eth0 inet static

address 192.168.0.1
netmask 255.255.255.0

How to copy a CD ROM in linux in Ubuntu

This how to will help you to make an iso image from your CDROM

1. Insert CD to be copied
2 Open a terminal

3 $ sudo umount /dev/cdrom0
(unmount the cd . Be careful about cdrom0 . It can be some thing else on your system. running mount with out arguments can help you to find out the cdrom device.)

4 $ sudo dd if=/dev/scd0 of=file.iso bs=2048 conv=notrunc

(the /dev/ listing may vary so be sure which is your cd. Also make sure that you have sufficient free space on the hard disk)

4. Once complete use your favourite .iso (k3b, brasaro, etc.) to burn the image back to another disk.

Monday, April 13, 2009

Downloading web pages with Downthemall


If you are using firefox to do internet browsing, DownthemAll is a cool plugin.
You install it from here. Once installed , this plugin adds two items to your right click menu. Look at the following picture.




When browsing a web page you can right click and then select the Down them All button. A new window pops up as shown below.


Set up the target diectory and then select the files/URLs to download. Enjoy easy download.

List of installed packages in Ubuntu 8.10

The list of installed packages in Ubunu/ debian can be see by the following command

# dpkg -l

I you want the list of packages along with the disk space they occupy use this variation.

# dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr | less
This can be very useful if you install lot of packages and later decide to remove some of them to recover space.

Tuesday, April 7, 2009

Blocking ads with adbloc extention in firefox

Adblock is a firefox extension which can save lot of internet traffic for you. Don't forget to install it if you have a monthly download limit.
This video shows how to install it.



Alternately you can look at this link

Disassembling programs with dissy

Dissy is a small utility which can be used to disassemble executable programs. It is actually a front end to objdump. On ubuntu objdump is provided by the binutils package.
You can install dissy with

sudo apt-get install dissy.


For trying out dissy, write a small C program as below.
int main()
{
printf("hello\n");
returns 0;
}

Compile it
$ gcc -o hello hello.c

Now invoke dissy as

$ dissy hello

You will get a graphical screen as below.


Hex editors in Ubuntu

Ghex is a cool hex editor that I some times use. You can install ghex like this.

Install it like this.
sudo apt-get install ghex

A menu entry will come under Applications->Programming->Hex Editor
Here is a screen shot of Ghex.



Alternately, you can install khexedit.

sudo apt-get install khexedit


Screen shots of khexedit are shown below.