DEV Community

Indra Wahyu
Indra Wahyu

Posted on

Function to Create New Directory and Jump Into it Immediately

I want to create command to create new directory and jump into it immediately and I found this solution. Just add md () { mkdir "$1" && cd "$1" ; } function to .bashrc. Oke this is my intruction.

Go to home directory

cd ~
Enter fullscreen mode Exit fullscreen mode

Open and edit .bashrc file with vim or nano

nano .bashrc
Enter fullscreen mode Exit fullscreen mode

Add function to end of command. Exit with ctrl+x y and enter

md () { mkdir "$1" && cd "$1" ; }
Enter fullscreen mode Exit fullscreen mode

Reopen your terminal or restart it

exec bash -l
Enter fullscreen mode Exit fullscreen mode

Now you can create new directory and jump into it immediately with

md directory_name
Enter fullscreen mode Exit fullscreen mode

reference

Top comments (0)