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

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 linedo lno=$[${lno:=0}+1] echo $lno $linedone[/code]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 knowEvery 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 9600Use ‘mtr’ when debugging network issues:$ mtr www.google.comRe-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^600ls -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.txtReturn your current IP address:$ curl ifconfig.men.n.n.nTyping a long command on the command line? Convert it to your favorite editor using: cntrl-x cntrl-eUpdate the default editor on Ubuntu.$ sudo update-alternatives --config editorThere 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 modePress enter to keep the current choice[*], or type selection number:Watch Star Wars via telnet$ telnet towel.blinkenlights.nl

Related posts

Browse more
We haven't published any posts