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.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018