bash bash循环遍历所有子目录中的递归
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9353126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash loop through all find recursively in sub-directories
提问by qwertymk
I have a bash script that looks like the following:
我有一个如下所示的 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
Now I need it to go through all subdirectories in public_html
so it should run on:
现在我需要它遍历所有子目录,public_html
所以它应该运行:
/public_html/index.php
/public_html/forums/status.php
/public_html/really/deep/file/in/many/sub/dirs/here.php
What do I change FILES=public_html/*.php
to in order to do that?
FILES=public_html/*.php
为了做到这一点,我要改变什么?
Also I need to check to make sure that there is at least one file or else it prints
我还需要检查以确保至少有一个文件,否则它会打印
Processing *.php file...
回答by sgibb
FILES=$(find public_html -type f -name '*.php')
IMPORTANT:Note the single quotes around the *.php
to prevent shell expansion of the *
.
重要提示:注意周围的单引号*.php
以防止*
.
回答by Jarryd
FILES=`find public_html -type d`
$FILES will now be a list of every single directory inside public_html.
$FILES 现在将是 public_html 中每个目录的列表。