如何在特定目录(-mmin -1)中查找特定文件(txt)?
/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您的回答!这是我使用的,看起来效果很好:
thanks for the answers! This is what I used, and what seems to be working just fine:
基本上你的脚本中有一些错误,除此之外,我认为这不是正确的方法。
无论如何,首先,你应该这样做:(
注意使用 ` 而不是 ')
这将在 $found 中存储 /Users 下的目录列表, -mmin 1 参数仅列出最后一分钟创建的那些目录,如果这是正确的,只需再次添加即可。
后来你需要循环结果来查找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:
(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:
That way isn't the best for me, I think that you can just do:
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.