Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. #TIL In bash you can create multiple (nested) directories with a single compact line:

#TIL In bash you can create multiple (nested) directories with a single compact line:

Scheduled Pinned Locked Moved Uncategorized
tilbashlinuxcli
16 Posts 13 Posters 88 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cark@social.tchncs.deC cark@social.tchncs.de

    #TIL In bash you can create multiple (nested) directories with a single compact line:

    ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

    ❯ tree
    .
    └── a
    ├── b
    ├── c
    │    ├── x
    │   └── y
    └── d
    ├── e
    └── f

    #bash #linux #cli

    C This user is from outside of this forum
    C This user is from outside of this forum
    carl@chaos.social
    wrote last edited by
    #7

    @cark modifiziert -p is idempotent, too!
    Like in any Script:

    tempdir_for_script=“/tmp/tempdir_for_$(basename “$0”)

    Later in the script:
    <result to log> >> “$tempdir_for_script”

    Last line of script:
    # rm -r “$tempdir_for_script”

    (Remove # after full debugging)

    1 Reply Last reply
    0
    • cark@social.tchncs.deC cark@social.tchncs.de

      #TIL In bash you can create multiple (nested) directories with a single compact line:

      ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

      ❯ tree
      .
      └── a
      ├── b
      ├── c
      │    ├── x
      │   └── y
      └── d
      ├── e
      └── f

      #bash #linux #cli

      matthias@gruene.socialM This user is from outside of this forum
      matthias@gruene.socialM This user is from outside of this forum
      matthias@gruene.social
      wrote last edited by
      #8

      @cark tested on OpenIndiana. Works in the same way. Thx!

      matthias@gruene.socialM 1 Reply Last reply
      0
      • matthias@gruene.socialM matthias@gruene.social

        @cark tested on OpenIndiana. Works in the same way. Thx!

        matthias@gruene.socialM This user is from outside of this forum
        matthias@gruene.socialM This user is from outside of this forum
        matthias@gruene.social
        wrote last edited by
        #9

        @cark and also with fish on cachyos linux.

        1 Reply Last reply
        0
        • cark@social.tchncs.deC cark@social.tchncs.de

          #TIL In bash you can create multiple (nested) directories with a single compact line:

          ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

          ❯ tree
          .
          └── a
          ├── b
          ├── c
          │    ├── x
          │   └── y
          └── d
          ├── e
          └── f

          #bash #linux #cli

          compfu@mograph.socialC This user is from outside of this forum
          compfu@mograph.socialC This user is from outside of this forum
          compfu@mograph.social
          wrote last edited by
          #10

          @cark Man, curly braces in bash creep me out. I can never remember whether that you need a comma to separate items (because glob expansion produces spaces). If I tried to build that command I would get errors or subfolders called ; 😅

          1 Reply Last reply
          0
          • cark@social.tchncs.deC cark@social.tchncs.de

            #TIL In bash you can create multiple (nested) directories with a single compact line:

            ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

            ❯ tree
            .
            └── a
            ├── b
            ├── c
            │    ├── x
            │   └── y
            └── d
            ├── e
            └── f

            #bash #linux #cli

            montyzuma@mastodontech.deM This user is from outside of this forum
            montyzuma@mastodontech.deM This user is from outside of this forum
            montyzuma@mastodontech.de
            wrote last edited by
            #11

            @cark Shell expansion magic

            1 Reply Last reply
            0
            • cark@social.tchncs.deC cark@social.tchncs.de

              #TIL In bash you can create multiple (nested) directories with a single compact line:

              ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

              ❯ tree
              .
              └── a
              ├── b
              ├── c
              │    ├── x
              │   └── y
              └── d
              ├── e
              └── f

              #bash #linux #cli

              danimrich@mastodon.socialD This user is from outside of this forum
              danimrich@mastodon.socialD This user is from outside of this forum
              danimrich@mastodon.social
              wrote last edited by
              #12

              @cark This is a very neat trick of the sort where you learn about it and then spend five minutes thinking of a scenario where it would be useful. 😉

              1 Reply Last reply
              0
              • cark@social.tchncs.deC cark@social.tchncs.de

                #TIL In bash you can create multiple (nested) directories with a single compact line:

                ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

                ❯ tree
                .
                └── a
                ├── b
                ├── c
                │    ├── x
                │   └── y
                └── d
                ├── e
                └── f

                #bash #linux #cli

                proedie@mastodon.greenP This user is from outside of this forum
                proedie@mastodon.greenP This user is from outside of this forum
                proedie@mastodon.green
                wrote last edited by
                #13

                @cark Whaaaat?! 🤯

                1 Reply Last reply
                0
                • R relay@relay.infosec.exchange shared this topic
                • cark@social.tchncs.deC cark@social.tchncs.de

                  #TIL In bash you can create multiple (nested) directories with a single compact line:

                  ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

                  ❯ tree
                  .
                  └── a
                  ├── b
                  ├── c
                  │    ├── x
                  │   └── y
                  └── d
                  ├── e
                  └── f

                  #bash #linux #cli

                  jantheowassink@chaos.socialJ This user is from outside of this forum
                  jantheowassink@chaos.socialJ This user is from outside of this forum
                  jantheowassink@chaos.social
                  wrote last edited by
                  #14

                  @cark Brilliant, thanks for sharing!

                  1 Reply Last reply
                  0
                  • cark@social.tchncs.deC cark@social.tchncs.de

                    #TIL In bash you can create multiple (nested) directories with a single compact line:

                    ❯ mkdir -p a/{b,c/{x,y},d/{e,f}}

                    ❯ tree
                    .
                    └── a
                    ├── b
                    ├── c
                    │    ├── x
                    │   └── y
                    └── d
                    ├── e
                    └── f

                    #bash #linux #cli

                    arnotron@noc.socialA This user is from outside of this forum
                    arnotron@noc.socialA This user is from outside of this forum
                    arnotron@noc.social
                    wrote last edited by
                    #15

                    @cark I love brace expressions to create backup copies or rename files. E.g. cp a{,.bak} or me b{,.old}

                    cark@social.tchncs.deC 1 Reply Last reply
                    0
                    • arnotron@noc.socialA arnotron@noc.social

                      @cark I love brace expressions to create backup copies or rename files. E.g. cp a{,.bak} or me b{,.old}

                      cark@social.tchncs.deC This user is from outside of this forum
                      cark@social.tchncs.deC This user is from outside of this forum
                      cark@social.tchncs.de
                      wrote last edited by
                      #16

                      @arnotron

                      I was not aware of this technique until recently... and yes I see also there are more use cases e.g. with `cp` and `mv`. 👍

                      1 Reply Last reply
                      0
                      • R relay@relay.infosec.exchange shared this topic
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups