Working in Linux requires one to work with the terminal a lot. IMHO creating shorthand for frequently used commands really helps a lot. For instance I've always wanted the mkdir command to create and CD into the new directory as one operation. In this post I am going to do just that.
The bash script is simple:
#/bin/sh if [ "$1" != "" ] then if [ -d $1 ] then cd $1 else mkdir $1 cd $1 fi else cd $1 fi
Store this file in a file /usr/bin/md.sh. Storing the file here makes it available to all users.
The next this is to create an alias like this:
alias md='. md.sh'
The reason we need add the . before md is because we want to execute the script in the current shell, if we don't do this any commands like cd will have no effect on the current shell.
That's all well and good but we also want this ability everytime we login. For this we need to edit the .bashrc file.
cd ~ vi .bashrc # paste alias md='. md.sh' at the end of the file. Remeber to remove the #
Here is a screenshot of the .bashrc file:
Now logoff and logon and see if shiny new md command works. Happy Linuxing!