我想对目录进行基本循环。它有一组已知的子目录。其中每个都有一个具有相同名称的文件列表(file1,file2 ... file6)。对于那些拥有全部6个的人,我想重新运行为这些特定目录创建它们的进程。获取没有6个文件的目录的lsit最简单的方法是什么?
for file in $oDir/* ; do
find which dont have ALL 6 files [file1, file2, file3, file4, file5, file6]
done
答案 0 :(得分:3)
你可以:
#!/bin/bash
shopt -s nullglob ## Do not allow presenting the pattern if no file is found.
for dir in "$oDir"/*; do
[[ -d $dir ]] || continue ## Skip those that aren't directories.
files=("$dir"/file[1-6]) ## Match those files.
if [[ ${#files[@]} -ne 6 ]]; then
# This directory has at least one of those 6 files missing.
# Do something.
:
fi
done
确保将脚本作为bash运行。将其作为./script.sh
(基于标题)或bash script.sh
运行。
答案 1 :(得分:2)
也许是
的内容if [ $(ls file* | wc -l) -ne 6 ]; then ...