ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
find /path -name "pattern" က folder tree တစ်ခုလုံး ရှာပြီး name pattern နဲ့ ကိုက်ညီတဲ့ ဖိုင်/folder အားလုံးကို ပြပါတယ် — real-time search ဖြစ်လို့ folder ကြီးမှာ နည်းနည်းကြာနိုင်ပေမယ့် အတိအကျပါ။ locate ကတော့ system ကတည်းက pre-built database ကို search လုပ်တာမို့ ပိုမြန်ပါတယ်, ဒါပေမယ့် ဖိုင်အသစ်ဖန်တီးလိုက်ရင် database update (updatedb) လုပ်မှ တွေ့ပါလိမ့်မယ်။ which ကတော့ ရှာနည်း ကွာပါတယ် — command တစ်ခုက ဘယ် folder က program ဖိုင်ကို run နေတာလဲ ပြပေးပါတယ် (ဥပမာ which python3)။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Downloads folder ထဲမှာ report.pdf ဆိုတဲ့ဖိုင် ဘယ်မှာလဲ ရှာချင်ရင် find ~/Downloads -name "report.pdf" လို့ ရိုက်ပါ။ .txt file အားလုံးကို folder တစ်ခုလုံးထဲ ရှာချင်ရင် find . -name "*.txt" (wildcard * သုံးလို့ရ) — . က 'အခုနေရာ' ဆိုတဲ့ shortcut ဖြစ်ကြောင်း ယခင်အခန်းမှာ တွေ့ခဲ့ပြီးပါပြီ။ Python ဘယ်နေရာက run နေမှန်း သိချင်ရင် which python3 ရိုက်ကြည့်ပါ — output က /usr/bin/python3 လို path တစ်ခု ပြန်ပါလိမ့်မယ်။
အတူတူ terminal ထဲ စမ်းမယ်
find ~/Downloads -name "report.pdf"
find . -name "*.txt"
locate hostname
which python3ကိုက်ညီတဲ့ ဖိုင်များ full path (ဥပမာ /home/user/Downloads/report.pdf) အနေနဲ့ ပေါ်လာမည်။၅ မိနစ် စမ်းကြည့်
practice folder ထဲ .txt file ၂ ခု ဖန်တီးပြီး find . -name "*.txt" နဲ့ ရှာကြည့်ပါ။
သတိလေးတစ်ချက်
find ရဲ့ pattern ထဲမှာ * သုံးရင် quote ("") ထဲထားပါ, မထားရင် shell က * ကို ကိုယ်တိုင် ဖွင့်ချနိုင်ပြီး ရလဒ် မမျှော်လင့်ဘဲ ကွဲနိုင်ပါတယ်။