One command to create and change directory

前端 未结 9 1091
执念已碎
执念已碎 2020-12-08 19:07

I\'m searching for just one command — nothing with && or | — that creates a directory and then immediately cha

相关标签:
9条回答
  • 2020-12-08 19:35

    You did not say if you want to name the directory yourself.

    cd `mktemp -d`
    

    Will create a temp directory and change into it.

    0 讨论(0)
  • 2020-12-08 19:39

    I don't think this is possible but to all people wondering what is the easiest way to do that (that I know of) which doesn't require you to create your own script is:

    mkdir /myNewDir/
    cd !$
    

    This way you don't need to write the name of the new directory twice.

    !$ retrieves the last ($) argument of the last command (!).

    (There are more useful shortcuts like that, like !!, !* or !startOfACommandInHistory. Search on the net for more information)

    Sadly mkdir /myNewDir/ && cd !$ doesn't work: it retrieves the last of argument of the previous command, not the last one of the mkdir command.

    0 讨论(0)
  • 2020-12-08 19:45
    mkdir temp ; cd temp ; mv ../temp ../myname
    

    You can alias like this:

    alias mkcd 'mkdir temp ; cd temp ; mv ../temp ../'
    
    0 讨论(0)
提交回复
热议问题