bash脚本读取目录中的所有文件

bash脚本读取目录中的所有文件

问题描述:

如何遍历目录?我知道在/var/files中有f的;执行echo $ f; done; 的问题是它将一次吐出目录中的所有文件.我想一步一步地去做,并能用$ f变量做点什么.我认为while循环最适合该循环,但是我无法弄清楚如何实际编写while循环.

How do I loop through a directory? I know there is for f in /var/files;do echo $f;done; The problem with that is it will spit out all the files inside the directory all at once. I want to go one by one and be able to do something with the $f variable. I think the while loop would be best suited for that but I cannot figure out how to actually write the while loop.

任何帮助将不胜感激.

一个简单的循环应该正在工作:

A simple loop should be working:

for file in /var/*
do
    #whatever you need with "$file"
done

请参见 bash文件名扩展