2022-02-23 shell 获取当前目录及子目录的文件名

#!/bin/bash
# 获取文件夹下所有文件
folder="./"

softfiles=$(find $PWD | xargs ls -ld $folder)
for sfile in ${softfiles}; do
    if [[ "$sfile" =~ json$ ]]; then # 此处是获取json后缀的文件
        echo "${sfile}"
    fi
done

使用方式:

  1. 将上述shell脚本保存到【aaa.sh】 文件
  2. 将aaa.sh文件放到需要执行的文件目录下
  3. 执行shell命令 sh aaa.shsh aaa.sh > name.txt
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章