1

Let's say I have the following command:

mkdir directory && cd directory

I normally do this a lot during the day so I'm wondering if there is a simpler shorter way of doing this.

Does anybody know?

frietkot
  • 891
  • 12
  • 28

2 Answers2

2

Put the following code in your ~/.bashrc or ~/.zshrc :

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

Then in your shell, enter the following command mkcd foo. As you can see, this function need one argument which are the name of the directory.

alifirat
  • 2,899
  • 1
  • 17
  • 33
2

you can call last argument by &_

mkdir directory && cd $_

this is result

system:/tmp # mkdir directory && cd $_
system:/tmp/directory #
vlp
  • 583
  • 3
  • 8