微慑信息网

linux 遍历文件夹下所有文件

 

1、linux 遍历文件夹下所有文件

#! /bin/bash
function read_dir(){
for file in `ls $1` #注意此处这是两个反引号,表示运行系统命令
do
 if [ -d $1"/"$file ] #注意此处之间一定要加上空格,否则会报错
 then
 read_dir $1"/"$file
 else
 echo $1"/"$file #在此处处理文件即可
 fi
done
} 
#读取第一个参数
read_dir $1

 

2、demo测试遍历目录

#!/bin/sh  
list_alldir(){  
    for file2 in `ls -a $1`  
    do  
        if [ x"$file2" != x"." -a x"$file2" != x".." ];then  
            if [ -d "$1/$file2" ];then  
                echo "$1/$file2" >>getdir.txt  
                list_alldir "$1/$file2"  
            fi  
        fi  
    done  
}  
  
list_alldir ./ctf

 

本文标题:linux 遍历文件夹下所有文件
本文链接:
(转载请附上本文链接)
https://vulsee.com/archives/vulsee_2020/0410_11005.html
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » linux 遍历文件夹下所有文件
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

微慑信息网 专注工匠精神

访问我们联系我们