bash script read all the files in directory

后端 未结 3 766
花落未央
花落未央 2021-02-02 07:36

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

3条回答
  •  猫巷女王i
    2021-02-02 08:05

    A simple loop should be working:

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

    See bash filename expansion

提交回复
热议问题