Directory Navigation Tips in Linux

Linux, bash October 7th, 2008

Many of us just use cd, cd .., cd <dir> to navigate through the file system in Linux. Directory or file-system navigation can be simplified by using following commands -

1) Many times we are in some directory say /home/user/foo and we need to go to the directory /usr/share/bar . After completing tasks in this directory, if one needs to get back to the previous directory, he would type in ‘cd /home/user/foo’ . Won’t it be far easy if we had some kind of back button as in Nautilus or Windows Explorer ? Its already there in Linux. Just type in
$ cd -
and you will reach back to the previous directory.

2) Another important tool to make navigation easier is ‘pushd’ and ‘popd’. Say you are in some directory /home/user/foo1 and then you wish to navigate to /home/user/foo2 and then to /home/user/foo3
After all these you need to back to previous directories. You can use pushd and popd like this :

$ pwd
/home/user/foo1
$ pushd .
$ cd /home/user/foo2
$ pushd .
$ cd /home/user/foo3

Now to get back to previous directories -
$ popd
$ pwd
/home/user/foo2

pushd actually push its argument directory to a stack and popd changes the current directory to the one on top of the stack.

Hope you enjoyed these tips.

I can share and save my status messages !

gtalkbots, microblogging October 2nd, 2008

I love showing off my status messages of gtalk. I often set witty messages, latest (probably unheard) news, my latest blog links in my status. Many a times I wish to log those messages to make a life stream. Wouldn’t it be great if I could someday check, what was my status on my last birthday ! Or may be, I would love to remember those moments when I used to impress my girlfriend by weird status messages. Status messages are no more just for “available” , “busy” and “idle”. Its like microblogging now.

Thanks to http://gtalkbots.com . Now I can save all my status messages and even share it to the world. So now I can have my life stream saved without any pain of logging in to the website. I simply had to add bots@gtalkbots.com to my buddy list and register once in the website. Simple !

This bot is intelligent as well. I can save any notes link etc just by messaging “<notes> Anything I want to save.”

This site is even providing widgets for my blog. Check out the two widgets in the side panel of this page. There are two gtalkbots.com widgets on my blog. One of them shows my last 10 status messages and the other one displays the last 10 shared status message of the world.

I can even ‘track’ my friends’ status messages. Isnt all these great ??

Check out my gtalkbots page: http://gtalkbots.com/spsneo

Hope you will also love this service and give a try at least.

Google Launching a New Browser : Chrome

Chrome, Firefox, Google September 2nd, 2008

Google today confirmed that they are going to launch a new browser : chrome tomorrow. Check out the Google’s official blog here.
The web browser will compete with Internet Explorer and Mozilla Firefox.
Google has also launched a comic which describes the need and feature of the new browses.

Here’s the link to the comic http://www.google.com/googlebooks/chrome

Well, Google has already released the “Chrome” Browser for Windows Vista and XP

Download it here

I don’t know why Google doesn’t release products for Linux :(

Waiting for Chrome (Linux Version)

Reusing SSH connection

Linux, SSH August 25th, 2008

Very often, while working on a network node via SSH, we need multiple connections to the same node. For example, say you are connected to a node A, and then you need to transfer a file to the same node from your local machine. Then we have to scp, which establishes a fresh connection to that machine and one has to enter the password again. So, it takes some time as well as it is irritating to enter password again and again.

Here’s the remedy :

Open the file /etc/ssh/ssh_config on your local machine as root to edit. Or if you are not the root user, you can create a fileĀ  ~/.ssh/configĀ  for user level SSH configurations.

Add the following lines at the end of the file you opened just now:

ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p

Save the file and you are done !!

Now check out (One can try it this way) -Open a terminal and connect to a server :

$ ssh s.siddharth@202.141.81.145

The connection gets established after entering the proper password.

Then in another terminal try to copy a file from your local machine to the same server :

$ scp -r ~/pintos s.siddharth@202.141.81.145

This time, you don’t need to wait for a fresh connection, neither you will have to enter the password again. File transfer starts instantaneously. SSH shared the already established connection.
Similarly you can open another terminal without waiting and entering the password again.

One can check out more configurations for SSH by checking out the man pages of ssh_config
$ man ssh_config

Hope you liked this tip !!

Download Files Larger Than The Download Limit

Linux, curl, proxy August 18th, 2008

Yesterday I had to download a file of size 232 MB. As I connect to the Internet via proxy and the authorities have restricted the file size download limit to 150 MB, I had to find some alternative. Similar scenarios are there in almost all Educational Institutions.

I was searching for the solution, somebody told me about JGet (a Multithreaded Java Software), but it hogs up a lot of system resources. I was in search of an alternate solution, then somebody on ##linux in irc.freenode.net told me about curl. Though I had heard of it earlier as well and I used it to automate web browsing like posting form data etc. But this time when I went through the man pages of curl, I realized how powerful is curl.

There are hundreds of options for CURL. I will just demonstrate you the one option which can help you download files of almost any size.

Lets start off…

In this example I am trying to download 32 Bit Fedora Live CD iso image. In this example, what we will do is download a part of file in one connection. After downloading all files we will concatenate them. This is what almost any Download manager software does.

To download a part of file theres an option -r/ --range available in curl which lets us specify the range of bytes of the file to be downloaded.

Range can be specified in following ways :
curl -r 0-499
This specifies to download first 500 bytes
curl -r 500-999
This specifies to download bytes starting from 500 to 999.
curl -r -500
specifies to download last 500 bytes.
curl -r 500-
specifies to download the bytes from offset 500 and forward

There are few more options. Check out the man pages. ( I have copied the simple options here).

Now here I have to download Fedora live CD iso which is 691 MB in size. So, I will download 100 MB in each connection, like this:
curl -# -r 0-99999999 -o fedora.iso.part1 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 100000000-199999999 -o fedora.iso.part2 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 200000000-299999999 -o fedora.iso.part3 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 300000000-399999999 -o fedora.iso.part4 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 400000000-499999999 -o fedora.iso.part5 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 500000000-599999999 -o fedora.iso.part6 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

curl -# -r 600000000- -o fedora.iso.part7 http://download.fedoraproject.org/pub/fedora/linux/releases/9/Live/i686/Fedora-9-i686-Live.iso &

In the above code -# is to suppress the details of progress meter. You can ignore this option.

After all the files are downloaded, we need to concatenate them. This is quite simple.

$ cat fedora.iso.part? > fedora-9-live.iso
And your live CD iso image is ready as fedora-9-live.iso
To verify the file has been downloaded and concatenated correctly you may verify the checksums before burning it to a CD/DVD.

This process could be automated if somehow by a simple shell script if we could get the file size before starting the downloaded. To accomplish this, I once again went through the man pages. And I found a useful option -I/ --head . This option fetches the HTTP-header only. One can easily get the file size as Content-Length from the HTTP headers. But, when I tried this through proxy servers I got a X-Squid-Error: ERR_TOO_BIG , so couldn’t determine the correct file size. And hence I am unable to automate the process. Anybody, any help ?? (please post it as comment).

Happy Downloading !!