Can't create folder using mkdir

5,962

The / character is used to separate the different directories, and it fails because the directory 2017 does not yet exist. To create nested directories with the parent directories created automatically, use

mkdir -p 2017/October/10
Share:
5,962
Teo Protoulis
Author by

Teo Protoulis

Updated on September 18, 2022

Comments

  • Teo Protoulis
    Teo Protoulis almost 2 years

    I want to create a folder following the below procedure:

    set folder 2017/October/10
    mkdir $folder
    

    But this isn't possible and I get the message:

    mkdir: cannot create directory '2017/October/10': No such file or directory
    

    I want to include that in script function! I could really use some help!

    EDIT: This just can't happen!

    • Teo Protoulis
      Teo Protoulis over 6 years
      Same result. It didn't work.
    • Panther
      Panther over 6 years
      That is not a good name, it will cause problems. You can try mkdir '2017/October/10' but imho better use a different delineate 2017.October.10 for exame
    • wjandrea
      wjandrea over 6 years
      I'd recommend ISO-8601 format for naming files and dirs, so in this case: 2017-10-10
    • thomasrutter
      thomasrutter over 6 years
      Forward slashes aren't allowed in file or directory names on any variant of Unix (including Linux). Even if individual filesystems support it (and the main ones don't), the operating system doesn't. I'd recommend dashes instead.
  • Teo Protoulis
    Teo Protoulis over 6 years
    I want the name of the directory to be 2017/October/10. I don't want to create a folder and then subfolders within it.
  • wjandrea
    wjandrea over 6 years
    @TeoProtoulis You can't do that. (Edit: sorry for the all-caps)
  • Teo Protoulis
    Teo Protoulis over 6 years
    @wjandrea Yes, I figured that out. Thanks anyway!