Bash

  • To process a file line-by-line
     while read i; do something-with-$i; done < filename 
  • To insert a character literally into a command first hit “Ctrl-v” followed by the character (For example Ctrl-v will insert a literal tab character)
  • Dealing with leading dashes in filenames: For example, if you have a file with name “-n”, then
    cat -n

    will lead to problems. Fix this by instead doing

    cat ./-n

Awk

  • Print lines matching a certain criteria
     cat file.txt | awk 'criteria' 

    where criteria could be something like:

     $1 > 100 

    or

     $2 ~/SomePattern/ 
  • Nicely formatted and justified output for piped commands. The following command left-justifies each column and allocates 15 spaces for first two columns each and 8 for the last
     somecmd | awk '{printf "%-15s%-15s-%-8s",$1, $2, $3}' 

Screen

  • Oops .. You hit Ctrl-S by mistake and screen doesn’t respond? What you have done is call XOFF and the terminal has stopped responding. To fix, hit Ctrl-q … and continue where you left off

Ubuntu system administration

  • Sometimes, the package that you wish to install has variants and the default one may not work for you. For example, the default vim package offered by Ubuntu (16.04 LTS) does not provide python scripting support and so I cannot use Ultisnips with it. Now, I can go customize a source based installation, but on searching the apt repository I can see that there is a version “vim-nox-py2” that does support python 2. Here’s how you search for available packages with apt.
     apt-cache search keyword 

     

Share This