Lesson 8 / الدرس 8
Finding files / العثور على الملفات
You know a file exists and not where it is. One command searches the tree by name, size or age — and it is the first command in this course whose arguments read like a sentence.
تعرف أن ملفًا موجود ولا تعرف أين. وأمر واحد يبحث في الشجرة بالاسم أو الحجم أو العمر — وهو أول أمر في هذه الدورة تُقرأ وُسَطاؤه كأنها جملة.
find takes a place to start and then a description of what you are looking for, and it walks everything underneath. Unlike the search box in a file manager it looks at the actual tree every time, so it never gives you a stale answer from an index built last week.
find موضعًا يبدأ منه ثم وصفًا لما تبحث عنه، ويمشي في كل ما تحته. وخلافًا لمربع البحث في مدير الملفات فهو ينظر في الشجرة الفعلية كل مرة، فلا يعطيك جوابًا قديمًا من فهرس بُني الأسبوع الماضي.find . -name "*.css" CSS files, from here down
find . -iname "readme*" case-insensitive
find . -type d -name "assets" directories only
find . -type f -size +10M files over ten megabytes
find . -mtime -7 changed in the last seven days
find . -name "*.log" -delete found, and removed
*.css — lesson 15 explains why leaving them off gives a different and confusing result. *.css — والدرس 15 يشرح لماذا يعطي تركهما نتيجة مختلفة ومربكة.The tests worth knowing
| Test | Matches | Example |
|---|---|---|
| -name "x" | Name matches exactly, wildcards allowed | -name "*.jpg" |
| -iname "x" | The same, ignoring capitals | -iname "*.JPG" |
| -type f | Ordinary files only | -type f -name "*.php" |
| -type d | Directories only | -type d -name "node_modules" |
| -size +10M | Larger than ten megabytes | -size +100M |
| -mtime -7 | Modified fewer than seven days ago | -mtime -1 |
| -empty | Empty files and directories | -type d -empty |
Tests combine, and listing two means both must be true. The signs matter: +10M is larger than, -10M is smaller, and a bare 10M means exactly ten.
+10M أكبر من، و-10M أصغر، و10M مجردة تعني عشرة بالضبط.find . -type f -size +10M -mtime -30
find commands take. Run the demonstration for three you will genuinely reuse.
find. شغّل العرض لثلاثة ستعيد استخدامها فعلًا.-delete في آخر find يحذف كل ما طابق، بلا تأكيد ولا قائمة. نفّذ الأمر مرة بدونه واقرأ ما يرجع — فمقصد find كله أنه يبلغ مواضع لم تكن تفكر فيها، وهذا بالضبط ما يجعله خطرًا حين تكون الكلمة الأخيرة حذفًا.Finding a command rather than a file
A different question: not "where is my file" but "where is the program that runs when I type this". which php prints the path of the php that would run, and type tells you more — whether it is a program, a built-in, or a shortcut you defined yourself. This becomes important the moment you have two versions of something installed, which lessons 17 and 20 come back to.
which php يطبع مسار php الذي سيعمل، وtype يخبرك أكثر — هل هو برنامج أم مدمج أم اختصار عرّفته أنت. وهذا يصير مهمًا في اللحظة التي يكون فيها لديك نسختان من شيء مثبتتان، ويعود إليه الدرسان 17 و20.find بطيئًا لأنه ينظر في كل شيء فعلًا. ضيّق نقطة البداية — find ~/projects بدل find / — فيرجع فورًا عادةً. والبحث من / يطبع أيضًا قائمة طويلة من أسطر "permission denied" لمجلدات لا تملكها، وهذا طبيعي وليس خطأً في أمرك.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
What does find . -type d -name "assets" look for?
find . -type d -name "assets"؟-type d restricts it to directories, and the two tests together mean both must be true. The . is the starting point: here.
-type d على المجلدات، والاختباران معًا يعنيان وجوب تحقق كليهما. و. هي نقطة البداية: هنا.
2.
Before adding -delete to a find command, what should you do?
-delete إلى أمر find، ماذا ينبغي أن تفعل؟The value of find is that it reaches places you had not considered. That is also why the list is worth reading before the last word deletes it.
find أنه يبلغ مواضع لم تفكر فيها. وهذا أيضًا سبب استحقاق القائمة للقراءة قبل أن تحذفها الكلمة الأخيرة.
3.
You type php and get an unexpected version. Which command tells you which one runs?
php فتحصل على نسخة غير متوقعة. أي أمر يخبرك أيها يعمل؟which prints the path of the program that would actually run. Lesson 17 explains how the shell decides.
which مسار البرنامج الذي سيعمل فعلًا. والدرس 17 يشرح كيف تقرر الـshell.Score / النتيجة: 0 / 3
Your task / مهمتك
Answer three real questions about your own machine with find: what are the five largest files in your home directory, what did you change in the last two days, and where is every copy of some file type you care about. Show the exact command and a trimmed version of what came back, and say what surprised you.
أجب ثلاثة أسئلة حقيقية عن جهازك بـfind: ما أكبر خمسة ملفات في مجلد منزلك، وما الذي غيّرته في آخر يومين، وأين كل نسخة من نوع ملفات يهمك. وأظهر الأمر بالضبط ونسخة مختصرة مما رجع، وقل ما الذي فاجأك.
- Three real commands, run on your own machine ثلاثة أوامر حقيقية منفَّذة على جهازك
- The output of each, trimmed but genuine مخرَج كل واحد، مختصرًا لكن حقيقيًا
- A sentence on what surprised you جملة عمّا فاجأك