如何在特定目录(-mmin -1)中查找特定文件(txt)?

发布于 2024-10-05 07:20:21 字数 455 浏览 9 评论 0原文

 /usr/local/bin/growlnotify -m 'Looking for subtitles...'
 found='find /Users -type d -mmin -1'
 found1='find $found/*.txt'

 if [ -d "$found1" ];
      then
     /usr/local/bin/growlnotify -m "Subtitles downloaded!"
   else
     /usr/local/bin/growlnotify -m "Could not download subtitles"
 fi

我正在尝试编写一个 bash 脚本,该脚本将找到应用程序下载字幕的文件夹,并使用咆哮通知用户它们是否存在。

$found 给了我一个目录列表,但我不知道如何到达我想要的目录..

请帮忙=)

对不起我的英语

 /usr/local/bin/growlnotify -m 'Looking for subtitles...'
 found='find /Users -type d -mmin -1'
 found1='find $found/*.txt'

 if [ -d "$found1" ];
      then
     /usr/local/bin/growlnotify -m "Subtitles downloaded!"
   else
     /usr/local/bin/growlnotify -m "Could not download subtitles"
 fi

I am trying to write a bash script that would locate the folder in which an app downloaded subtitles and inform user using growl if they are present or not.

$found gives me a list of directories, but I do not know how to get to the one I want..

Please help =)

Sorry for my english

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-10-12 07:20:22

感谢您的回答!这是我使用的,看起来效果很好:

for FILE in "$@"
do
if [ -e "${FILE%.*}.txt" ];
                then
                     /usr/local/bin/growlnotify -a iNapi -m "Napisy zostały pobrane!"
                else
                    /usr/local/bin/growlnotify -a iNapi -m "Nie udało się pobrać napisów."
            fi
done

thanks for the answers! This is what I used, and what seems to be working just fine:

for FILE in "$@"
do
if [ -e "${FILE%.*}.txt" ];
                then
                     /usr/local/bin/growlnotify -a iNapi -m "Napisy zostały pobrane!"
                else
                    /usr/local/bin/growlnotify -a iNapi -m "Nie udało się pobrać napisów."
            fi
done
预谋 2024-10-12 07:20:22

基本上你的脚本中有一些错误,除此之外,我认为这不是正确的方法。

无论如何,首先,你应该这样做:(

found=`find /Users -type d`

注意使用 ` 而不是 ')

这将在 $found 中存储 /Users 下的目录列表, -mmin 1 参数仅列出最后一分钟创建的那些目录,如果这是正确的,只需再次添加即可。

后来你需要循环结果来查找txt文件:

for d in $found; do
   #here you do ll or find for .txt files, using $d as dir
done

这种方式对我来说不是最好的,我认为你可以这样做:

find /Users -name *.txt

然后看看你得到了什么,查找输出将打印每个txt文件所在的目录驻留,这与您正在尝试做的事情相同,但只有一步。

Basically you have some errors in the script, besides them, I dont think it's the correct way to do it.

Anyway, first of, you should do:

found=`find /Users -type d`

(note the use of ` and not ')

That will store in $found a list of directories under /Users, the -mmin 1 param just list those dirs that were created in the last minute, if that's correct, just add it again.

Later that you need to loop the results to look for txt files:

for d in $found; do
   #here you do ll or find for .txt files, using $d as dir
done

That way isn't the best for me, I think that you can just do:

find /Users -name *.txt

and then see what you got, the find output will print the directory where each txt file resides and that's the same that you are trying to do, but only one step.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文