Finding files with find · إيجاد الملفات باستخدام find
Searching the whole tree
lsshows one folder.findsearches a folder and everything inside it, however deep:
.means "start in the current folder".findlists every file and folder it can reach.
البحث في الشجرة كاملة
lsيعرض مجلداً واحداً.findيبحث في مجلد وجميع ما بداخله، مهما كان عميقاً:
find .
.يعني "ابدأ من المجلد الحالي".findيعدد كل ملف ومجلد يمكن الوصول إليه.
Find by name
- Usually you want files matching a pattern. Use
-name:
- This finds every
.txtfile in the tree — even ones buried three folders down. - Quote the pattern (
"*.txt") so the shell passes it tofinduntouched.
العثور حسب الاسم
- عادةً ما تريد ملفات تطابق نمطاً معيناً. استخدم
-name:
find . -name "*.txt"
- هذا يجد كل ملف
.txtفي الشجرة — حتى تلك المدفونة داخل ثلاثة مجلدات. - ضع النمط بين علامتي تنصيص (
"*.txt") لكي يمرره القوقب إلىfindدون تغيير.
Why it is handy
- "Where did I put that file?" —
findanswers it in one line. - Combined with pipes, you can act on the results — for example count them with
wc -l.
لماذا هو مفيد
- "أين وضعت ذلك الملف؟" —
findيجيب عنه في سطر واحد. - مقترناً بالأنابيب، يمكنك التصرف في النتائج — على سبيل المثال عدها باستخدام
wc -l.
Common mistakes
find . -name "*.txt"searches by name from the current folder down.- Quote the pattern so the shell does not expand it first.
أخطاء شائعة
find . -name "*.txt"يبحث حسب الاسم من المجلد الحالي نزولاً.- ضع النمط بين علامتي تنصيص حتى لا يقوم القوقب بفك رمزه أولاً.
find walks the tree · find يتجول في الشجرة
find searches the whole tree below a directory. · find يبحث في كامل الشجرة تحت مجلد معين.
Find every .txt file, even deep inside subfolders, with find . -name "*.txt". (. means "start from here".) · جد كل ملف .txt، حتى عميقاً داخل المجلدات الفرعية، باستخدام find . -name "*.txt". (. تعني "ابدأ من هنا".)
You can also start the search from a subfolder. Find just the .txt files inside docs (and below) with find docs -name "*.txt". · يمكنك أيضاً بدء البحث من مجلد فرعي. جد فقط ملفات .txt داخل docs (وتحتها) باستخدام find docs -name "*.txt".