Wpis z mikrobloga

#linux #bash #shell #pomocy
Czołem, czy jest mi ktoś w stanie pomóc?
Muszę sformułować warunek w skrypcie w bashu, który zwraca true jeśli znalazł plik, false w przeciwnym wypadku.
Mam na razie tak:

if find $KATALOG -amin -$OPCJA1 -mmin -$OPCJA2 -name $PLIK -print -quit | grep -q .
then
echo "plik istnieje";

else
echo "plik nie istnieje";

fi

i działa to dobrze, ale dodatkowo muszę wyszukać grepem konkretny napis, używając prawdopodobnie:
-exec grep $ZAWARTOSC {} \;
Mój problem polega na tym, że nie wiem jak to połączyć, bo nie za bardzo rozumiem co robi powyższa linijka.
Dzięki za ewentualną pomoc!
  • 15
@gJakub: gdyby to było takie proste... muszę użyć find, wyszukać konkretną zawartość z dwoma dodatkowymi opcjami wyszukiwania. Zwykłe [ -f ] nie da rady.
@j4ace: z "man find":
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.
@belkotgit: problem w tym, że polecenie find /home/.* -name a.txt -exec grep "string" {} \;
w ogóle nie działa... a chciałbym, żeby działało. Co robie źle?
"/home/.*" jest zle, u mnie ta "gwizdka" psuje (przeszukuje caly filesystem), co ona ma oznaczac? jesli masz szukac tylko w /home to "/home" lub "/home/." powinno wystarczyc