Bash:在某些文件夹中查找文件,然后创建输出列表 [英] Bash: Look for files in certain folders and then create output lists

查看:47
本文介绍了Bash:在某些文件夹中查找文件,然后创建输出列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Bash的新手,我正在尝试在一组特定的文件夹中查找文件.我想为每个/check/文件夹中的图像文件创建一个txt报告.

I'm new to Bash, and I'm trying to find files in a certain set of folders. I want to create a txt report for image files in each /check/ folder.

这就是我一直在努力的事情:

Here's what I've been working with:

# Find images
for f in */check/ ; do
    find ./ -iname "*jpg*" -o -iname "*png*" > find_images.txt
        echo "finished $f"
done

我无法弄清楚如何仅查看名为"check"的子文件夹,并且我还想传递变量,以便获得以父文件夹命名的单独文本文件.有什么建议吗?

I can't figure out how to only look at subfolders named "check", and I also want to pass the variable so that I get separate text files named after the parent folders. Any suggestions?

推荐答案

您已经关闭,但没有使用 $ f ,该文件包含文件夹的名称:

You're close, but you're not using $f which contains the folder's name:

# Find images
for f in */check/ ; do
    # Removing front-slashes from $f to use in log name
    # http://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion
    log_f="${f//\//_}"

    # Only search inside $f, saving results to find_images_[foldername].txt
    find "$f" -iname "*jpg*" -o -iname "*png*" > "find_images_${log_f}.txt"

    echo "finished $f"
done

这篇关于Bash:在某些文件夹中查找文件,然后创建输出列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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