Monday, September 30, 2013

[Linux] Creating Shortkeys for Common Commands

In Linux, you can assign short keys to commands you are required to run more often. These are called ‘alias’ and could be added in your .bashrc file. This really helps in quickly doing things and also avoid unnecessary mistakes while writing the commands. Below are some example:

To list all the files in current directory, including hidden files, you can assign a short key for it, say "ls" like mentioned below:
alias ls="ls -a"

View some properties file at particular location:
alias vdp="vi $JBOSS_HOME/server/default/conf/props/some.properties"

To get the running process:
alias jbp="ps -ef | grep jboss"

To view logs:
alias tlog="tail -f $JBOSS_HOME/bin/nohup.out"

Remove some files inside a directory:
alias clrjb="rm -rf $JBOSS_HOME/server/default/work/jboss.web"

Changing directory:
alias jb="cd $JBOSS_HOME/bin"

Beside this, the most useful is one here under. You can use this as “update <relative_directory_path>” to perform some steps in a sequence, one after another. This is called 'function' in linux, and are slightly different from alias, as they expect argument to be passed to them.

function update () {
  cd $SRC_HOME/"$1";
  mvn clean install -DskipTests -o -e;
  cd $SRC_HOME/someOtherFolder;
  mvn clean generate-resources -o -e;
  cd $JBOSS_HOME/bin/;
  sh runit.sh;
  tail -f $JBOSS_HOME/bin/nohup.out;
}

To have these effective, run "source .bashrc" command. 

NOTE: $JBOSS_HOME is an environment variable set as follows:
export JBOSS_HOME=/home/systest/web/jboss/jboss-5.1.0.GA

Enjoy!

5 comments:

  1. Gr8 Sana,it saved lot of time and effort to do same thing again and again.

    ReplyDelete
  2. FESHOP ACC RU LEGIT FSH 2017 RU FESHOP.RU FESHOP18 FESHOP Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome!

    ReplyDelete
  3. Uniccshop sign up free loaded cracked accounts activated Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome!

    ReplyDelete
  4. importers data This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs…

    ReplyDelete