gpt4 book ai didi

bash循环遍历子目录中的所有查找

转载 作者:行者123 更新时间:2023-11-29 08:50:53 24 4
gpt4 key购买 nike

我有一个如下所示的 bash 脚本:

#!/bin/bash
FILES=public_html/*.php # */ stupid syntax highlighter!
for f in $FILES
do
echo "Processing $f file..."
# take action on each file.
done

现在我需要它遍历 public_html 中的所有子目录,所以它应该运行在:

/public_html/index.php
/public_html/forums/status.php
/public_html/really/deep/file/in/many/sub/dirs/here.php

我要将 FILES=public_html/*.php 更改为什么才能做到这一点?

我还需要检查以确保至少有一个文件,否则它会打印

Processing *.php file...

最佳答案

FILES=$(find public_html -type f -name '*.php')

重要:请注意 *.php 周围的单引号,以防止 * 的 shell 扩展。

关于bash循环遍历子目录中的所有查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9353126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com