How little you know, and some useful commands for the week

Early in my career, I was writing a shell script and needed to print a line-number for each line in a text file. I ended up coming up with some function that did just what I needed.

I don’t recall the exact method, but it was something like:

[code]cat file | while read line
echo $lno $line

I was quite happy with the solution, until I realized that I could have just run ‘cat -n file’.

A few takeaways:

A better solution already exists, keep looking.
The more you learn, the more you realize how little you know

Every week, I still find new commands, new methods, and alternate ways to accomplish things. Below are a few items I found this week that you may also find helpful.

Connect directly to your serial console, and log the session.
# screen -L /dev/ttyS0 9600

Use ‘mtr’ when debugging network issues:
$ mtr

Re-run a command changing a parameter quickly:
$ ls -l 500.*
-rw-r--r-- 1 nwilkens nwilkens 0 2011-03-13 11:32 500.lst
-rw-r--r-- 1 nwilkens nwilkens 0 2011-03-13 11:32 500.txt
$ ^500^600
ls -l 600.*
-rw-r--r-- 1 nwilkens nwilkens 0 2011-03-13 11:32 600.lst
-rw-r--r-- 1 nwilkens nwilkens 0 2011-03-13 11:32 600.txt

Return your current IP address:
$ curl

Typing a long command on the command line? Convert it to your favorite editor using:
cntrl-x cntrl-e

Update the default editor on Ubuntu.
$ sudo update-alternatives --config editor
There are 6 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
0 /usr/bin/ng 80 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/emacs23 0 manual mode
4 /usr/bin/ng 80 manual mode
* 5 /usr/bin/vim.basic 30 manual mode
6 /usr/bin/vim.tiny 10 manual mode

Press enter to keep the current choice[*], or type selection number:

Watch Star Wars via telnet
$ telnet