让我们考虑一下您当前的工作目录中有以下10个文件夹:
tree .
.
├── 1
├── 10
├── 2
├── 3
├── 4
├── 5
├── 6
├── 7
├── 8
└── 9
您可以运行以下命令来创建文件:
for d in `find . -mindepth 1 -maxdepth 1 -type d`; do touch "$d"/test.txt; done
输出:
tree .
.
├── 1
│ └── test.txt
├── 10
│ └── test.txt
├── 2
│ └── test.txt
├── 3
│ └── test.txt
├── 4
│ └── test.txt
├── 5
│ └── test.txt
├── 6
│ └── test.txt
├── 7
│ └── test.txt
├── 8
│ └── test.txt
└── 9
└── test.txt
10 directories, 10 files
说明:
find . -mindepth 1 -maxdepth 1 -type d如果省略-mindepth 1,将获得当前工作文件夹下所有精确为1级的文件夹,因为您.将被选中,因此将在当前工作目录中创建一个文件,如果您省略,-maxdepth 1则将在任意深度级别递归创建文件,-type d将仅允许对目录进行过滤。
然后,您可以使用循环来创建文件,甚至xargs命令就足够了