Saturday, 30 August 2014

Alias command on Unix - why am I late to the party ?

So I regularly make use of this Linux command: -

history | cut -c 8-

to get the Bash history but without the numbers.

Before

  131  /opt/IBM/WebSphere/AppServer/bin/sibDDLGenerator.sh -system db2 -version 9.7 -platform unix -schema MONCM00 -statementend ";" -user db2user1 >> ~/createMESchemas.sql
  132  /opt/IBM/WebSphere/AppServer/bin/sibDDLGenerator.sh -system db2 -version 9.7 -platform unix -schema MONME00 -statementend ";" -user db2user1 >> ~/createMESchemas.sql
  133  db2 -tvf createMESchemas.sql


After

/opt/IBM/WebSphere/AppServer/bin/sibDDLGenerator.sh -system db2 -version 9.7 -platform unix -schema MONCM00 -statementend ";" -user db2user1 >> ~/createMESchemas.sql
/opt/IBM/WebSphere/AppServer/bin/sibDDLGenerator.sh -system db2 -version 9.7 -platform unix -schema MONME00 -statementend ";" -user db2user1 >> ~/createMESchemas.sql
db2 -tvf createMESchemas.sql


See, easy documentation :-)

However, I can never remember the format of the improved history command, so I end up opening a text file on my Mac to find it.

So why don't I use the alias command, I hear you say ?

Well, I do now :-)

This is the relevant alias command: -

alias hist='history | cut -c 8-'

which now gives me a shortened command ( so I actually type less ! ) which achieves my requirement.

On it's own, the alias command shows me ALL of my aliases: -

alias

alias hist='history | cut -c 8-'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'


Guess what I've added to my .bashrc :-)

No comments: