views:

1574

answers:

4

How exactly can I create a new directory using Emacs? What commands do I use? (If possible, please provide an example)

+20  A: 
  • to create the directory dir/to/create, type:

    M-x make-directory RET dir/to/create RET
    
  • to create directories dir/parent1/node and dir/parent2/node, type:

    M-! mkdir -p dir/parent{1,2}/node RET
    

    It assumes that Emacs's inferior shell is bash.

  • or in a Dired mode

    +
    

    It doesn't create nonexistent parent directories.

    Example:

    C-x d *.py RET ; shows python source files in the CWD in `Dired` mode
    + test RET     ; create `test` directory in the CWD
    

    CWD stands for Current Working Directory.

  • or just create a new file with non-existing parent directories using C-x C-f and type:

    M-x make-directory RET RET
    
J.F. Sebastian
+3  A: 

C-x C-f to open a directory in "dired" mode, then "+" to create a directory.

Just Some Guy
I assume the '+' goes at the end of whatever the new file path directory is going to be?
Ray Vega
No. See my answer.
J.F. Sebastian
OK. I see now. Thanks!
Ray Vega
+2  A: 

You can also run single shell commands using C-!

You're basically sending a string to the command line so you don't get any nice auto-completion but it's useful if you know how to perform an action through the command line but don't know an Emacs equivalent way.

M-! mkdir new_dir
Cristian
Did you mean `M-!` ?
J.F. Sebastian
A: 

You can use M-x create-directory inside of any buffer, not necessarily a dired buffer. It is a lisp function you can use as well.

Jonathan Arkell