mkdir and cd

Many times, i find myself making and moving to a directory quite a bit, normally I use something like this
$ mkdir ~/dir && cd ~/dir
$ mkdir -p create/new/dir && cd create/new/dir
You can’t have a simple BASH script that reads “mkdir $1 && cd $1” because it would only switch to the directory while running as a child process instead of actually switching to the directory.
However there is a quick and easy way to combine the tasks, add a function mkcd() to your .bashrc.
$ cat >> ~/bashrc
function mkcd(){
[ -n “$1” ] && mkdir -p “$@” && cd “$1”;


Author: Ali MEZGANI

My name is MEZGANI Ali. I was born back in 1978 in Rabat Morocco. My interests are Debian Linux , programming , science and music.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s