The mkdir (make directory) command in the Unix, DOS, OS/2 and Microsoft Windows operating systems is used to make a new directory. The underlying system call is also called mkdir(). In DOS, OS/2 and Windows the command is often abbreviated to md.
Questions tagged [mkdir]
1200 questions
2823
votes
17 answers
How to mkdir only if a directory does not already exist?
I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that…

Spike Williams
- 35,795
- 13
- 48
- 60
1018
votes
12 answers
mkdir -p functionality in Python
Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a solution other than a system call. I am sure the code is less than 20 lines, and I am wondering if someone has already written it?

Setjmp
- 27,279
- 27
- 74
- 92
386
votes
20 answers
Is there a way to make mv create the directory to be moved to if it doesn't exist?
So, if I'm in my home directory and I want to move foo.c to ~/bar/baz/foo.c , but those directories don't exist, is there some way to have those directories automatically created, so that you would only have to type
mv foo.c ~/bar/baz/
and…

Paul Wicks
- 62,960
- 55
- 119
- 146
321
votes
3 answers
How to create new folder?
I want to put output information of my program to a folder. if given folder does not exist, then the program should create a new folder with folder name as given in the program. Is this possible? If yes, please let me know how.
Suppose I have given…
alex
166
votes
3 answers
Bash mkdir and subfolders
Why I can't do something like this? mkdir folder/subfolder/ in order to achive this I have to do:
mkdir folder
cd folder
mkdir subfolder
Is there a better way to do it?

Uffo
- 9,628
- 24
- 90
- 154
148
votes
7 answers
mkdir if not exists using golang
I am learning golang(beginner) and I have been searching on both google and stackoverflow but I could not find an answer so excuse me if already asked, but how can I mkdir if not exists in golang.
For example in node I would use fs-extra with the…

Alfred
- 60,935
- 33
- 147
- 186
146
votes
8 answers
How to create a directory and give permission in single command
How to create a directory and give permission in single command in Linux?
I have to create lots of folder with full permission 777.
Commands
mkdir path/foldername
chmod 777 path/foldername
I don't like to create and give permission in two…

whiterose
- 4,391
- 8
- 24
- 18
137
votes
5 answers
How to create nested directories using Mkdir in Golang?
I am trying to create a set of nested directories from a Go executable such as 'dir1/dir2/dir3'. I have succeeded in creating a single directory with this line:
os.Mkdir("." + string(filepath.Separator) + c.Args().First(),0777);
However, I have no…

tommymcdonald
- 1,528
- 2
- 10
- 12
134
votes
7 answers
Vim: Creating parent directories on save
If I invoke vim foo/bar/somefile but foo/bar don't already exist, Vim refuses to save.
I know I could switch to a shell or do :!mkdir foo/bar from Vim but I'm lazy :)
Is there a way to make Vim do that automatically when it saves the buffer?

Damien Pollet
- 6,488
- 3
- 27
- 28
94
votes
6 answers
What is equivalent to Linux mkdir -p in Windows?
In Linux, mkdir -p creates a folder tree.
What is the equivalent option in Windows to create a folder tree? Is there any?

Renjith G
- 6,307
- 9
- 27
- 26
89
votes
1 answer
Does Ruby have mkdir -p?
Possible Duplicate:
How to create directories recursively in ruby?
In Ruby, how could I do:
mkdir -p cool/beans
Here's what I came up with:
Dir.mkdir('cool') unless File.directory?('cool')
cool_beans_path = File.join('cool',…

ma11hew28
- 121,420
- 116
- 450
- 651
80
votes
16 answers
Recursive mkdir() system call on Unix
After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the…

Alex Marshall
- 10,162
- 15
- 72
- 117
76
votes
6 answers
Why can't PHP create a directory with 777 permissions?
I'm trying to create a directory on my server using PHP with the command:
mkdir("test", 0777);
But it doesn't give full permissions, only these:
rwxr-xr-x

Sjwdavies
- 4,079
- 7
- 38
- 43
68
votes
3 answers
python mkdir to make folder with subfolder?
This works:
mkdir('folder')
but this doesn't
mkdir('folder/subfolder')
error:
WindowsError: [Error 3] The system cannot find the path specified: 'folder/subfolder'

b7875787
- 681
- 1
- 5
- 3
59
votes
11 answers
os.mkdir(path) returns OSError when directory does not exist
I am calling os.mkdir to create a folder with a certain set of generated data. However, even though the path I specified has not been created, the os.mkdir(path) raises an OSError that the path already exists.
For example, I…

Quanquan Liu
- 1,427
- 3
- 16
- 30