linux shell创建目录、遍历子目录

1、创建目录

代码1:

#!/bin/bash
#如果没有tmp_dir目录则创建
static_dir="/web/fyunw.com/static"
if [ ! -d $staic_dir ]; then
  sudo mkdir -p -m 755 $static_dir
  echo "sudo mkdir -p -m 755 ${static_dir} done"
fi

2、遍历子目录

代码2:

#!/bin/bash
static_dir="/web/fyunw.com/static"
for tmp_file in $(ls $static_dir)
do
  echo $tmp_file
  source_dir="${static_dir}/${tmp_file}/v1"
  target_dir="/web_static/${tmp_file}/v1"
  if [[ ! -d $source_dir && -d $target_dir ]]; then
    sudo ln -s $target_dir v1
done

原文地址:https://www.cnblogs.com/zqifa/p/shell-dir-1.html