这将深入一个子目录.内部for循环将遍历封闭的文件和目录.该if声明将排除目录.您可以设置选项以包含隐藏文件和目录(shopt -s dotglob).
shopt -s nullglob
for dir in /some/dir/*/
do
for file in "$dir"/*
do
if [[ -f $file ]]
then
do_something_with "$file"
fi
done
done
Run Code Online (Sandbox Code Playgroud)
这将是递归的.您可以使用该-maxdepth选项限制深度.
find /some/dir -mindepth 2 -type f -exec do_something {} \;
Run Code Online (Sandbox Code Playgroud)
使用-mindepth排除当前目录中的文件,但它包含下一级(及以下,取决于-maxdepth)的文件.
| 归档时间: |
|
| 查看次数: |
8174 次 |
| 最近记录: |