【发布时间】:2020-03-13 17:31:46
【问题描述】:
我在 shell 编程和正则表达式方面并不是很先进。我需要忽略名称与正则表达式匹配的文件。我已经尝试了很多东西。这是我的功能:
for file in $1/* <-------- This matches every file, i need it to ignore something stored in variable like: ARG="file.txt"
do
if [ -d "$file" ]; then
dir_count=$((dir_count+1))
dir_file_counter $file
fi
#if file is directory then increment DIRCOUNT and recursively look into that directory
if [ -f "$file" ]; then
det_size $file
file_count=$((file_count+1))
fi
done
我尝试过消极的环顾四周,但这并没有帮助: 当我使用如下参数时:arg="(!? text.txt).*" 它只是将其添加到地址中并且不匹配任何内容。 有人可以帮忙吗? 谢谢
【问题讨论】:
-
如果您需要做的只是在排除模式的同时递归地计算文件数,您可以使用
find、grep -v和wc的组合。类似find path/to/search -type f | grep -v 'pattern_to_exclude' | wc -l。