Tuesday, December 5, 2023

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long.

mkdir long-name-of-directory 
cd long-name-of-directory

I checked what are the shourcuts for this. specially is there an one line command to both create and move in to the directory. Actually there is no one line command. But we can create one in our shell. 

If you are using bash, following function can be added

mkcd () { mkdir "$1" cd "$1" }

If you are using csh, you have to add an alias because C shell doesn't support function.
 
alias mkcd 'mkdir $PWD/\!:1;cd $PWD/\!:1'

If you are can't configure your enviorenment we can use following commands.
 
mkdir long-name-of-directory 
cd !^ 

Let me know If you have any other solutions.

No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...