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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs