开发者

How to find a specific file(txt) in a specific directory(-mmin -1)?

 /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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜