Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Saturday, March 15, 2008

Carriage Return (CR) & Line Feed (LF)

Today while playing with `od` - a command-line tool to dump file data in octal and other formats - and looking at 012 (octal code of \n) it just came to my mind to find out the difference between carriage return (\r) and line feed (\n) characters and how do they date back in history. I got my answer from the very first attempt in Google which directly led me to Yahoo answers.

The two characters emulate the two main actions in typewriters. Carriage-Return which moves the cursor back to the beginning of the line corresponds to the moving of typewriter’s carriage to the initial leftmost position, whereas Line-Feed which move the cursor to the next line corresponds to the rolling up of paper by one line. The combination of both i.e. CR-LF were initially used in Teletypewriters to move the print head back to the beginning of new line.

Even though the two still performs the same action in standard output and printers, not all operating systems use both of them. *nix based systems use \n, Mac uses \r, whereas Windows uses both \r\n. This is a reasons why *nix text documents look weird in windows.

Thursday, January 10, 2008

Firefox loading blank pages

I had been facing this weird firefox problem for quite a few days in my linux box (Ubuntu 7.04 - the Feisty Fawn). After connecting to my ISP and browsing for few minutes suddenly all the URL requests were ending up in blank pages. Earlier I thought this was a problem with my ISP. But when I noticed that messenger and all the command-line tools (wget, lynx etc.) were working fine I understood that actual problem was something else. Considering the presence of some bug I first tried to upgrade the firefox (v2.0.08 to v2.0.0.11). Unfortunately this didn't solve the problem. I tried analyzing the http response headers using wget but couldn't gain much. Ultimately I had to resort to lynx with yahoo search as google was also dying with "400 Bad Request" message. After one or two attempts I got its solution in a forum. The problem was occurring with the pages responding with http 302 status. Some people also mentioned to experience the same problem with pages using script based redirection. Anyhow, the reason for this was attributed to some buggy firefox extension. With this knowledge it was easy to resolve the problem. Trying disabling each firefox extension one by one. I was too desperate to fix the issue ASAP, so I disabled all the extensions in one go. Voila! it worked and everything restored back to normal.

Saturday, January 5, 2008

Changing MAC address in Linux

Changing MAC addresses of network adapters on machines have become a mundane thing these days. For those using debian and ubuntu there are multiple ways to achieve the same.
ifconfig <interface> hw <hardware class> <mac address>
Example:
# /etc/init.d/networking stop
# ifconfig eth0 hw ether 00:00:00:A9:0A:3C
# /etc/init.d/networking start
The MAC address set via this way would be temporary and lost next time you reboot. The more better and persistent solution is to add the following line with interface settings in /etc/network/interfaces.
hwaddress <hardware class> <mac address>
Example:
iface eth0 inet static
address x.x.x.x
netmask 255.x.x.x
gateway x.x.x.x
hwaddress ether 00:00:00:A9:0A:3C
Don't forget to restart network using /etc/init.d/networking restart, or rebooting machine after this. There is another command-line tool available these days named macchanger, a GNU/Linux utility for viewing/manipulating the MAC address of network interfaces, which can also be used apart from the above mentioned two methods.
# /etc/init.d/networking stop
# macchanger -m 00:00:00:A9:0A:3C eth0
# /etc/init.d/networking start