Linux 一次创建一个完整的目录树

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17674406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:16:38  来源:igfitidea点击:

Creating a full directory tree at once

linuxbash

提问by James

I would like to create a complex directory structure in a bash script and was under the impression that the following would work:

我想在 bash 脚本中创建一个复杂的目录结构,并认为以下方法可行:

mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}

Which would create:

这将创建:

          tmpdir
    ________|______
   |        |      |
branches   tags  trunk
                   |
                 sources
               ____|_____
              |          |
          includes     docs

However when I run my script I end up with:

但是,当我运行我的脚本时,我最终得到:

tmpdir
   |
trunk

Is there a quick and easy way to do this or am I going to have to resort to

有没有一种快速简便的方法来做到这一点,或者我将不得不求助于

mkdir -p tmpdir/trunk/sources/includes
mkdir -p tmpdir/trunk/sources/docs
mkdir -p tmpdir/branches
mkdir -p tmpdir/tags

采纳答案by Grzegorz ?ur

Change shebang to

将shebang更改为

#!/bin/bash

to run the script with bash as it supports brace expansion.

使用 bash 运行脚本,因为它支持大括号扩展。

The problem is that you are using shell that does not support it. Your /bin/shdoes not point to /bin/bashbut to something like /bin/dash.

问题是您使用的外壳不支持它。你的/bin/sh不是指向/bin/bash而是指向类似的东西/bin/dash

https://wiki.ubuntu.com/DashAsBinSh#A.7B

https://wiki.ubuntu.com/DashAsBinSh#A.7B

回答by Evhz

You can try to use treefor this.

您可以尝试为此使用

sudo apt install tree
tree -d .

It's a great tool printing console-like tree directory structure:

这是一个很棒的工具,可以打印类似控制台的树目录结构:

├── logstash   
│?? ├── afolder
│?? ├── bfolder  
│?? └── mappings  
├── elastic 
│?? └── afolder  
└── reports  
 ?? └── afolder