Sunday, 25 October 2015

How To: Automatically cd to a directory after you create it



The majority of the times that I create a directory I would then change to that directory. To make this happen automatically I add the following to my .bashrc :

mkcd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

Example :

$ mkcd ~/tmp/FOO
$ pwd
/home/cw/tmp/FOO

How To: Display your Top 10 cli commands




Its useful to be able to see which command you use most often on a Linux box. I add the following to my .bashrc :

cli-top-10() {
  history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head
}

Example output :

57 ls
49 cd
26 mv
25 curl
18 wget
17 rm
15 sudo
13 packer
12 docker
12 vim

How To: Permanently Display line numbers for Vim or Vi




It can be very useful when troubleshooting to display line numbers in Vim or Vi. To enable this in your ~/.vimrc file add :

:set number

which can also be manually set within Vim or Vi. Within the editor to remove the line numbers :


:set nonumber