3

First I do this:

mkdir firstFolder

Then:

mkdir firstFolder/secondFolder

Here an error occurs. The command line interface returns "incorrect syntax". What is the right syntax?

I am using Bash upon Cmdr in Windows 7.

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Webwoman
  • 181
  • 1
  • 2
  • 8

2 Answers2

2

You think it's Bash but maybe it's not. CMD in Windows has mkdir too but the directory separator is \.

Try

mkdir firstFolder\secondFolder

In Bash the backslash would be interpreted as (unnecessary) escape character, the command would create a directory named firstFoldersecondFolder. If it creates secondFolder inside firstFolder then you're not in Bash.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • Okay I have understood that Cmder - https://www.cmder.net - was a kind of bash for Windows – Webwoman Nov 26 '19 at 21:58
  • 1
    @Webwoman It's a terminal emulator. I don't know the program at all but I expect one can choose somehow which shell it starts. Useful resource: [*What is the difference between shell, console, and terminal?*](https://superuser.com/q/144666/432690) – Kamil Maciorowski Nov 26 '19 at 22:06
1

You can use this to create the whole tree in one go and avoid the error:

mkdir -p firstFolder/secondFolder/thirdFolder

The -p parameter is defined as:

-p, --parents     no error if existing, make parent directories as needed

Note: This depends on how close to the Linux standard is implemented mkdir in your environment.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • I thought this was a `-p` issue as well, but as the original poster confirms in [this comment](https://superuser.com/questions/1505364/create-nested-directory-from-parent-directory-with-bash#comment2274600_1505364), switching from forward slash (`/`) to a backslash (`\`) fixed the issue. – Giacomo1968 Nov 26 '19 at 21:28
  • 1
    @JakeGould: Misled by the reference to bash. – harrymc Nov 26 '19 at 21:31