bash脚本读取目录中的所有文件 [英] bash script read all the files in directory

查看:67
本文介绍了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文件名扩展

这篇关于bash脚本读取目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆