ako pracuje "find"?

Michal Weinfurtner weinfurt na securities.cz
Čtvrtek Květen 24 17:13:28 CEST 2001


Jan Marek wrote:

> Dobry den,
>
> Mozna delam neco spatne, ale pokud si vlezu do root adresare a
> zadam si coby root prikaz:
>
> find / -name qmai* -print
>
> Tak mi to najde to stejne jako
>
> find / -name qmai\* -print
>
> To jen takove experimentalni overeni... Doufam, ze to usmiri
> zastance escapovani i zastance setreni klavesy '\' ;-)))
>

Nedelate spatne nic, jen jste si neprecetl man bash jak jsem doporucoval.

Cituji MAN BASH :

   Pathname Expansion
       After word splitting, unless the -f option has been set, bash scans each
word
       for the characters *, ?, and [.  If one of these characters appears,
then the
       word is regarded as a pattern, and replaced  with  an  alphabetically
sorted
       list  of pathnames matching the pattern.  If no matching pathnames are
found,
       and the shell variable allow_null_glob_expansion is unset, the word  is
left
       unchanged.   If  the  variable  is set, and no matches are found, the
word is
       removed.  ......

Vsimnete si zejmena vety "If no matching pathnames are found, and the shell
variable allow_null_glob_expansion is unset, the word  is  left unchanged. "
!!  To znamena ze bash nejprve, jakmile narazi na hvezdicku v prikazovem radku,
zkusi ji nahradit celou cestou. V tomto prikladu v AKTUALNIM adresari, protoze
pred slovem  qmai nemate specifikovanu zadnou cestu. Pokud se vyskytne v
aktualnim adresari nejaky soubor nebo adresar ktery obsahuje qmai pak se slovo
qmai* timto nahradi , ( je-li jich vice nahradi se setridenym seznamem ) ALE
pokud  tam nic takoveho neni, preda shell slovo qmai* v nezmenene podobe ( vse
zavisi na promenne allow_null_glob_expansion ) .

Porad si neuvedomujete, ze ten kdo nahrazuje znak * a pred kym se to musi
ochranovat tim obracenym lomitkem neni find ale shell !! To znamena ze by jste,
kdyz uz, tak mel uvest verzi shellu a ne findu.

Zkuste si :

#cd ~
#find / -name send* -ls &
#ps -aufxwww |grep find
#find / -name send\* -ls &
#ps -aufxwww |grep find

#> ./sendmail.txt

#find / -name send* -ls &
#ps -aufxwww |grep find
#find / -name send\* -ls &
#ps -aufxwww |grep find


Michal




Další informace o konferenci Linux