Linux 如何编写bash脚本,递归扫描子目录并列出当月的当前日期的文件?
我需要编写一个简单的bash脚本来递归地扫描子目录(从当前目录开始),列出名称包含当月当前日期的所有文件的名称。 我对bash脚本非常陌生 我写了下面的脚本,但没有得到任何东西Linux 如何编写bash脚本,递归扫描子目录并列出当月的当前日期的文件?,linux,bash,grep,Linux,Bash,Grep,我需要编写一个简单的bash脚本来递归地扫描子目录(从当前目录开始),列出名称包含当月当前日期的所有文件的名称。 我对bash脚本非常陌生 我写了下面的脚本,但没有得到任何东西 #!/bin/bash for i in $find* do if grep -rq date +%d $i; then echo $i fi done 使用查找。例如: find . -type f -iname "*09*" -iname“*09*”告诉它只查找包含“09”的文件。您
#!/bin/bash
for i in $find*
do
if grep -rq date +%d $i; then
echo $i
fi
done
使用
查找。例如:
find . -type f -iname "*09*"
-iname“*09*”
告诉它只查找包含“09”的文件。您可以将其替换为您拥有的月份中的某一天
-type f
告诉它只返回文件,而不返回目录
还有很多选择。阅读forfind
使用date
命令获取变量中的当前日期,然后运行find
:
d=$(date '+%d')
cd /base/dir
find . -name "*$d*" -type f
例如,人可以找到并寻找<代码>-mtime
。