Single “mkdir” command to make a new directory and change to that directory at the same time? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Combined `mkdir` and `cd`? [duplicate]

    4 answers



  • Is there a one-liner that allows me to create a directory and move into it at the same time?

    10 answers



Quick question:



Is it possible to use "mkdir" to make a new directory AND change to that directory at the same time using a single 'mkdir' command?



Whole question:



I have this question:



What single Linux “mkdir” command could replace the sequence of commands?
mkdir a
cd a
mkdir b
cd b
mkdir c
cd ../..


My answer is:



 mkdir a b c && cd c


Is there a single "mkdir" command, without using any other commands, perhaps with some flags or something, I can use to make AND change directory at the same time?










share|improve this question









New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by muru, Stephen Kitt linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 22 at 7:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
    – muru
    Nov 22 at 7:05






  • 1




    Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
    – G-Man
    Nov 22 at 7:41










  • I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
    – G-Man
    Nov 22 at 7:45










  • @G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
    – muru
    Nov 22 at 7:56










  • @muru: Yes, those.
    – G-Man
    Nov 22 at 7:58














up vote
0
down vote

favorite













This question already has an answer here:



  • Combined `mkdir` and `cd`? [duplicate]

    4 answers



  • Is there a one-liner that allows me to create a directory and move into it at the same time?

    10 answers



Quick question:



Is it possible to use "mkdir" to make a new directory AND change to that directory at the same time using a single 'mkdir' command?



Whole question:



I have this question:



What single Linux “mkdir” command could replace the sequence of commands?
mkdir a
cd a
mkdir b
cd b
mkdir c
cd ../..


My answer is:



 mkdir a b c && cd c


Is there a single "mkdir" command, without using any other commands, perhaps with some flags or something, I can use to make AND change directory at the same time?










share|improve this question









New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by muru, Stephen Kitt linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 22 at 7:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
    – muru
    Nov 22 at 7:05






  • 1




    Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
    – G-Man
    Nov 22 at 7:41










  • I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
    – G-Man
    Nov 22 at 7:45










  • @G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
    – muru
    Nov 22 at 7:56










  • @muru: Yes, those.
    – G-Man
    Nov 22 at 7:58












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Combined `mkdir` and `cd`? [duplicate]

    4 answers



  • Is there a one-liner that allows me to create a directory and move into it at the same time?

    10 answers



Quick question:



Is it possible to use "mkdir" to make a new directory AND change to that directory at the same time using a single 'mkdir' command?



Whole question:



I have this question:



What single Linux “mkdir” command could replace the sequence of commands?
mkdir a
cd a
mkdir b
cd b
mkdir c
cd ../..


My answer is:



 mkdir a b c && cd c


Is there a single "mkdir" command, without using any other commands, perhaps with some flags or something, I can use to make AND change directory at the same time?










share|improve this question









New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












This question already has an answer here:



  • Combined `mkdir` and `cd`? [duplicate]

    4 answers



  • Is there a one-liner that allows me to create a directory and move into it at the same time?

    10 answers



Quick question:



Is it possible to use "mkdir" to make a new directory AND change to that directory at the same time using a single 'mkdir' command?



Whole question:



I have this question:



What single Linux “mkdir” command could replace the sequence of commands?
mkdir a
cd a
mkdir b
cd b
mkdir c
cd ../..


My answer is:



 mkdir a b c && cd c


Is there a single "mkdir" command, without using any other commands, perhaps with some flags or something, I can use to make AND change directory at the same time?





This question already has an answer here:



  • Combined `mkdir` and `cd`? [duplicate]

    4 answers



  • Is there a one-liner that allows me to create a directory and move into it at the same time?

    10 answers







linux mkdir






share|improve this question









New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 22 at 10:30









Rui F Ribeiro

38.3k1475126




38.3k1475126






New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 22 at 7:03









Mandingo

225




225




New contributor




Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mandingo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




marked as duplicate by muru, Stephen Kitt linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 22 at 7:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by muru, Stephen Kitt linux
Users with the  linux badge can single-handedly close linux questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 22 at 7:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
    – muru
    Nov 22 at 7:05






  • 1




    Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
    – G-Man
    Nov 22 at 7:41










  • I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
    – G-Man
    Nov 22 at 7:45










  • @G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
    – muru
    Nov 22 at 7:56










  • @muru: Yes, those.
    – G-Man
    Nov 22 at 7:58
















  • And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
    – muru
    Nov 22 at 7:05






  • 1




    Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
    – G-Man
    Nov 22 at 7:41










  • I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
    – G-Man
    Nov 22 at 7:45










  • @G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
    – muru
    Nov 22 at 7:56










  • @muru: Yes, those.
    – G-Man
    Nov 22 at 7:58















And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
– muru
Nov 22 at 7:05




And unix.stackexchange.com/questions/125385/combined-mkdir-and-cd ...
– muru
Nov 22 at 7:05




1




1




Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
– G-Man
Nov 22 at 7:41




Your question title and your question body don't match.  The question body says (paraphrased) can I combine these three mkdir commands into a single mkdir command? If you understood the list of six commands (which, apparently, you don't), you would see that you end up in the top-level directory where you started.
– G-Man
Nov 22 at 7:41












I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
– G-Man
Nov 22 at 7:45




I believe that this question has been misinterpreted and closed incorrectly.  (OK, it probably is a duplicate, but not of any of the questions linked here.) Filipe Brandenburger's answer is the right answer to this question.
– G-Man
Nov 22 at 7:45












@G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
– muru
Nov 22 at 7:56




@G-Man dupe of unix.stackexchange.com/q/84191 or unix.stackexchange.com/questions/49263/recursive-mkdir then?
– muru
Nov 22 at 7:56












@muru: Yes, those.
– G-Man
Nov 22 at 7:58




@muru: Yes, those.
– G-Man
Nov 22 at 7:58










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










The question you present of using a single mkdir command to do the same as the other steps doesn't really involve changing directories. It ends with cd ../.. which brings you back to the directory you were in at the start.



In effect, that sequence of commands creates a directory a, then a directory b within it (in other words, a/b), then a directory c within the just created b (in other words, a/b/c.)



You can do the same with a single mkdir command that creates the nested directories after creating their parents:



mkdir a a/b a/b/c


Another way is using mkdir's -p option, which will create the parent directories if necessary, so you don't need to specify them:



mkdir -p a/b/c


This doesn't answer your question in the title (for mkdir + cd look at the duplicates from the comments), but addresses the question in your text, about the equivalent single mkdir command for that sequence, in which at the end of the sequence the directory is the same as at the start of it.






share|improve this answer
















  • 1




    This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
    – G-Man
    Nov 22 at 7:40










  • @G-Man Great minds think alike 😁
    – Filipe Brandenburger
    Nov 22 at 7:41






  • 1




    Oh, I misunderstood the question, oops! Thanks for the reply!
    – Mandingo
    Nov 22 at 7:53










  • @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
    – ctrl-alt-delor
    Nov 22 at 10:13


















up vote
1
down vote













Do it as a function:



mkcdir ()

mkdir -p -- "$1" &&
cd -P -- "$1"






share|improve this answer








New contributor




Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    The question you present of using a single mkdir command to do the same as the other steps doesn't really involve changing directories. It ends with cd ../.. which brings you back to the directory you were in at the start.



    In effect, that sequence of commands creates a directory a, then a directory b within it (in other words, a/b), then a directory c within the just created b (in other words, a/b/c.)



    You can do the same with a single mkdir command that creates the nested directories after creating their parents:



    mkdir a a/b a/b/c


    Another way is using mkdir's -p option, which will create the parent directories if necessary, so you don't need to specify them:



    mkdir -p a/b/c


    This doesn't answer your question in the title (for mkdir + cd look at the duplicates from the comments), but addresses the question in your text, about the equivalent single mkdir command for that sequence, in which at the end of the sequence the directory is the same as at the start of it.






    share|improve this answer
















    • 1




      This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
      – G-Man
      Nov 22 at 7:40










    • @G-Man Great minds think alike 😁
      – Filipe Brandenburger
      Nov 22 at 7:41






    • 1




      Oh, I misunderstood the question, oops! Thanks for the reply!
      – Mandingo
      Nov 22 at 7:53










    • @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
      – ctrl-alt-delor
      Nov 22 at 10:13















    up vote
    2
    down vote



    accepted










    The question you present of using a single mkdir command to do the same as the other steps doesn't really involve changing directories. It ends with cd ../.. which brings you back to the directory you were in at the start.



    In effect, that sequence of commands creates a directory a, then a directory b within it (in other words, a/b), then a directory c within the just created b (in other words, a/b/c.)



    You can do the same with a single mkdir command that creates the nested directories after creating their parents:



    mkdir a a/b a/b/c


    Another way is using mkdir's -p option, which will create the parent directories if necessary, so you don't need to specify them:



    mkdir -p a/b/c


    This doesn't answer your question in the title (for mkdir + cd look at the duplicates from the comments), but addresses the question in your text, about the equivalent single mkdir command for that sequence, in which at the end of the sequence the directory is the same as at the start of it.






    share|improve this answer
















    • 1




      This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
      – G-Man
      Nov 22 at 7:40










    • @G-Man Great minds think alike 😁
      – Filipe Brandenburger
      Nov 22 at 7:41






    • 1




      Oh, I misunderstood the question, oops! Thanks for the reply!
      – Mandingo
      Nov 22 at 7:53










    • @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
      – ctrl-alt-delor
      Nov 22 at 10:13













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    The question you present of using a single mkdir command to do the same as the other steps doesn't really involve changing directories. It ends with cd ../.. which brings you back to the directory you were in at the start.



    In effect, that sequence of commands creates a directory a, then a directory b within it (in other words, a/b), then a directory c within the just created b (in other words, a/b/c.)



    You can do the same with a single mkdir command that creates the nested directories after creating their parents:



    mkdir a a/b a/b/c


    Another way is using mkdir's -p option, which will create the parent directories if necessary, so you don't need to specify them:



    mkdir -p a/b/c


    This doesn't answer your question in the title (for mkdir + cd look at the duplicates from the comments), but addresses the question in your text, about the equivalent single mkdir command for that sequence, in which at the end of the sequence the directory is the same as at the start of it.






    share|improve this answer












    The question you present of using a single mkdir command to do the same as the other steps doesn't really involve changing directories. It ends with cd ../.. which brings you back to the directory you were in at the start.



    In effect, that sequence of commands creates a directory a, then a directory b within it (in other words, a/b), then a directory c within the just created b (in other words, a/b/c.)



    You can do the same with a single mkdir command that creates the nested directories after creating their parents:



    mkdir a a/b a/b/c


    Another way is using mkdir's -p option, which will create the parent directories if necessary, so you don't need to specify them:



    mkdir -p a/b/c


    This doesn't answer your question in the title (for mkdir + cd look at the duplicates from the comments), but addresses the question in your text, about the equivalent single mkdir command for that sequence, in which at the end of the sequence the directory is the same as at the start of it.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 at 7:14









    Filipe Brandenburger

    6,5801730




    6,5801730







    • 1




      This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
      – G-Man
      Nov 22 at 7:40










    • @G-Man Great minds think alike 😁
      – Filipe Brandenburger
      Nov 22 at 7:41






    • 1




      Oh, I misunderstood the question, oops! Thanks for the reply!
      – Mandingo
      Nov 22 at 7:53










    • @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
      – ctrl-alt-delor
      Nov 22 at 10:13













    • 1




      This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
      – G-Man
      Nov 22 at 7:40










    • @G-Man Great minds think alike 😁
      – Filipe Brandenburger
      Nov 22 at 7:41






    • 1




      Oh, I misunderstood the question, oops! Thanks for the reply!
      – Mandingo
      Nov 22 at 7:53










    • @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
      – ctrl-alt-delor
      Nov 22 at 10:13








    1




    1




    This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
    – G-Man
    Nov 22 at 7:40




    This is the right answer. Of course, I'm a little biased, because it is remarkably similar to the answer I just finished typing in Notepad.  Good job on getting it in 25 minutes ahead of me!
    – G-Man
    Nov 22 at 7:40












    @G-Man Great minds think alike 😁
    – Filipe Brandenburger
    Nov 22 at 7:41




    @G-Man Great minds think alike 😁
    – Filipe Brandenburger
    Nov 22 at 7:41




    1




    1




    Oh, I misunderstood the question, oops! Thanks for the reply!
    – Mandingo
    Nov 22 at 7:53




    Oh, I misunderstood the question, oops! Thanks for the reply!
    – Mandingo
    Nov 22 at 7:53












    @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
    – ctrl-alt-delor
    Nov 22 at 10:13





    @G-Man Why are you typing it in notepad? Type it into the shell, see if it works.
    – ctrl-alt-delor
    Nov 22 at 10:13













    up vote
    1
    down vote













    Do it as a function:



    mkcdir ()

    mkdir -p -- "$1" &&
    cd -P -- "$1"






    share|improve this answer








    New contributor




    Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote













      Do it as a function:



      mkcdir ()

      mkdir -p -- "$1" &&
      cd -P -- "$1"






      share|improve this answer








      New contributor




      Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



















        up vote
        1
        down vote










        up vote
        1
        down vote









        Do it as a function:



        mkcdir ()

        mkdir -p -- "$1" &&
        cd -P -- "$1"






        share|improve this answer








        New contributor




        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        Do it as a function:



        mkcdir ()

        mkdir -p -- "$1" &&
        cd -P -- "$1"







        share|improve this answer








        New contributor




        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Nov 22 at 7:11









        Michael Prokopec

        59915




        59915




        New contributor




        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?