循环遍历目录中的所有文件 [英] Looping through all files in a directory
本文介绍了循环遍历目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个 shell 脚本,该脚本将遍历目录中的所有文件并回显put ${filename}".有人能指出我正确的方向吗?
I want to write a shell script that will loop through all the files in a directory and echo "put ${filename}". Can anyone point me in the right direction?
推荐答案
对于文件和目录,不是递归的
For files and directories, not recursive
for filename in *; do echo "put ${filename}"; done
仅用于文件(不包括文件夹),不递归
For files only (excludes folders), not recursive
for file in *; do
if [ -f "$file" ]; then
echo "$file"
fi
done
有关递归解决方案,请参阅 Bennet Yee 的回答.
For a recursive solution, see Bennet Yee's answer.
这篇关于循环遍历目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文