2

I have a working directory with a large number of subfolders (i.e 1190A, 1993A etc).

'/working/1190A'
'/working/1993A'

I would like to recursively create a certain directory tree within each subfolder. For example:

'/working/1190A/analysis/1'
'/working/1993A/analysis/1'
etc

Thanks.

4

3 回答 3

4

要强制系统创建目录树而不必创建每个级别,请添加-pmkdir命令。

因此,这可以工作:

for dir in list_of_folders
do
   mkdir -p $dir/your/directory/tree
   [ $? ] && echo "error on $dir" # if the dir could not be created, print error (thanks @hetepeperfan - see comments)
done

注意list_of_folders可以像 一样给出/working/1190A /working/1993A,也可以用find命令生成。这只是第一个版本,您最好适应您的特定要求。

于 2013-05-28T08:32:34.483 回答
2

这是一个班轮

cd /working
find . -maxdepth 1 -type d -exec  mkdir -p '{}'/analysis/1 \;
于 2013-05-28T08:41:03.273 回答
0
yourDirList=/working/*
for f in $yourDirList
do
    if [ -d $f ]
        mkdir -p $f/analysis/1
    fi
done
于 2013-05-28T08:37:59.257 回答