0

This seems like such a Day 0 problem. I need to create a 2-level folder structure.

I tried:

sudo mkdir parent/child
>>> mkdir: cannot create directory ‘parent/child’: No such file or directory
sudo mkdir -p parent/child
>>> mkdir: cannot create directory ‘parent’: Permission denied
4
  • Can I understand the objective? You want to make a directory called “parent” (for example), then create a directory inside “parent” called “child” (for example). Is this correct? Or do you want to make a directory that has a slash in its name? 🤔
    – matigo
    Jun 14 at 12:28
  • 2 folders, one inside the other Jun 14 at 12:33
  • 1
    In what directory are you trying to create parent/child ?
    – Soren A
    Jun 14 at 13:42
  • 3
    ... I wonder if it's on a NFS mount with root_squash or similar? Jun 14 at 14:01
0

Most file systems do not work in a fashion similar to S3 block storage, making the automatic generation of what appears to be a fully-qualified path an automagical process. Generally, to do what you are attempting to do, a person would perform these actions:

mkdir parent
mkdir parent/child

However, if you insist on doing this as a one-liner, you can try this:

mkdir -p ~/{parent/{child}}

What’s nice about this is that you can create multiple directories pretty much simultaneously:

mkdir -p ~/{parent/{child1,child2,child3},uncle,aunt,Morty}

This will give you lots of directories all at once, so long as you remember -p and the curly brackets 👍🏻

1
  • There is no reason I can think of on a regular Linux file system why mkdir -p foo/bar would not work. That's the entire point of the GNU -p option to mkdir. More importantly, if mkdir -p ~/{parent/{child}} works, then so does mkdir -p ~/parent/child the braces aren't doing anything useful here. In fact, they are breaking things: your command will create a directory called ~/{parent and a subdirectory in that named {child}}. Try it. Brace expansion only works with commas.
    – terdon
    Jun 15 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.