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

2022-02-23  本文已影响0人  alanwhy
#!/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
上一篇 下一篇

猜你喜欢

热点阅读