可能重复:
How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?
我正在使用此循环删除给定目录和子目录下的所有文件中的空行。但它不起作用
for file in /home/zubinan/public_html/src/Acme/*/*.php
do
sed '/^$/d' $file > tt
mv tt $file
done
It says Demo is a directory
答案 0 :(得分:1)
试试这个;
for fname in `find /home/zubinan/public_html/src/Acme/ -type f`
do
sed '/^$/d' $fname > tt
mv tt $fname
done
答案 1 :(得分:0)
如果要处理某个目录中的所有指定文件,可以使用此oneliner:
sed -i '/^$/d' `find /home/zubinan/public_html/src/Acme -name "*.php"`
答案 2 :(得分:0)
for f in $(find /home/zubinan/public_html/src/Acme -type f \( -iname *.php \));
do
relfilePath=${f:${#currentpath}:${#f}};
// use relfilePath here
done
答案 3 :(得分:0)
或试试这个:
find /home/zubinan/public_html/src/Acme/ -type f -name "*.php" -exec sed -e '/^$/d' -i \{\} \;