Script to create and change the directory

This is a small script which will create a directory provided by you and change the directory to it.

#!/bin/bash
read -p “Give the directory to create” VAR1
mkdir -p $VAR1 && cd $VAR1
echo “Present working directory is `pwd`”

Save the file and change the permissions cdmd.sh

chmod +x cdmd.sh


execute the cdmd.sh as below.

bash cdmd.sh

Create this one as function and call this function as a command

mdcd () { mkdir -p $1 && cd $1 } 

 Keep this function in ~/.bashrc file and save this file.

From now on words we can just use this command to make directory and change the directory.

How about changing  the existing directory and list the conent?

cdls () { cd $1 && ls $1; } 


change the directory and then list the folder content. Keep this function in the ~/.bashrc file for using it as a command.


The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.