'How to create folder and cd into it with one command
I forget a command,could someone tell me?
for example,
$ makdir project-one-business-dev-2
$ cd project-one-business-dev-2
I don't want to type project's name for twice cause it's too long (ps: I know I can use tab what if there are similar names?). It's believed that only one command can got it. you can get directly after you created a folder in a one line.
Solution 1:[1]
A process can't change the working directory of it's parent process. That makes it impossible for an external command like mkdir
to set the working directory of the calling shell to the newly created folder.
But you can create a bash function for that purpose. Put this for example into your .bashrc
:
mkcd() {
mkdir -p "${1}"
cd "${1}"
}
Solution 2:[2]
You can do it like this:
mkdir project-one-business-dev-2 && cd "$_"
for more information check out this post on AskUbuntu
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | James Hart |