Lesson 6 / الدرس 6
Creating and removing / الإنشاء والحذف
Making a file or a folder takes one short command. Removing one takes another — and that second command deserves more respect than any other in this course, because there is no undo.
إنشاء ملف أو مجلد يحتاج أمرًا قصيرًا واحدًا. وحذفه يحتاج آخر — وذلك الأمر الثاني يستحق احترامًا أكثر من أي أمر آخر في هذه الدورة، لأنه لا تراجع.
mkdir notes make a directory
mkdir -p site/assets/css make the whole chain, without complaining
touch notes/todo.txt make an empty file (or update its timestamp)
rmdir notes remove a directory — only if it is empty
rm notes/todo.txt remove a file
rm -r site remove a directory and everything in it
mkdir -p: without it, making site/assets/css fails unless site/assets already exists. mkdir -p: فبدونه يفشل إنشاء site/assets/css ما لم يكن site/assets موجودًا أصلًا.rm has no recycle bin
When you delete a file in a file manager it moves to a bin and you can change your mind. rm does not do that. It unlinks the file and the space becomes available for anything else to use. There is no command that undoes it, and recovery — if it is possible at all — is a specialist job on a disk you have stopped writing to.
rm لا يفعل ذلك. بل يفكّ ارتباط الملف فتصير مساحته متاحة لأي شيء آخر. ولا أمر يتراجع عن ذلك، والاستعادة — إن أمكنت أصلًا — عمل متخصص على قرص توقفت عن الكتابة عليه.ls على المسار نفسه بالضبط أولًا، ولا تحذف إلا ما أراك للتو. وفضّل rm -i الذي يسأل قبل كل ملف. ولا تكتب أبدًا وتحت أي ظرف rm -rf / أو rm -rf ~ — لا لترى ما يحدث، ولا من صفحة ويب لم تقرأها. فذلك الأمر يمحو كل ما تملك، وعلى خادم يمحو الموقع.$ ls old-drafts look first
draft-1.txt draft-2.txt
$ rm -r old-drafts then delete exactly that
Why rmdir still exists
rmdir removes a directory only when it is already empty, and refuses otherwise. That refusal is a feature: it is impossible to destroy anything you had forgotten was in there. When you mean "remove this empty folder", using rmdir instead of rm -r means a mistake becomes an error message rather than a loss.
rmdir لا يحذف المجلد إلا إن كان فارغًا أصلًا، ويرفض غير ذلك. وذلك الرفض ميزة: فمن المستحيل أن تدمّر شيئًا نسيت أنه هناك. وحين تقصد "احذف هذا المجلد الفارغ"، فاستخدام rmdir بدل rm -r يجعل الخطأ رسالةَ خطأ لا خسارة.
touch is the other command with a second job. On a file that does not exist it creates an empty one. On a file that does exist it changes the modification time and leaves the contents alone — which sounds pointless until you meet a build tool that decides what to rebuild by comparing timestamps.
touch هو الأمر الآخر ذو العمل الثاني. فعلى ملف غير موجود ينشئ ملفًا فارغًا. وعلى ملف موجود يغيّر وقت التعديل ويترك المحتوى — وهو ما يبدو بلا فائدة حتى تقابل أداة بناء تقرر ما تعيد بناءه بمقارنة الأوقات.mv old-thing ~/tmp-delete-me. فيخرج من طريقك، ويظل كل شيء يعمل إن تبيّن أنه كان مطلوبًا، وتستطيع حذفه حقًا الأسبوع القادم. والدرس 7 يغطي mv.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
What does mkdir -p site/assets/css do that mkdir alone does not?
mkdir -p site/assets/css ولا يفعله mkdir وحده؟Without -p the command fails unless every parent already exists. It also stops mkdir complaining about a directory that is already there.
-p يفشل الأمر ما لم يكن كل أب موجودًا أصلًا. وهو يمنع أيضًا شكوى mkdir من مجلد موجود سلفًا.
2.
Why prefer rmdir when you mean to remove an empty directory?
rmdir حين تقصد حذف مجلد فارغ؟The refusal is the whole value. rm -r would have taken the contents you had forgotten about without a word.
rm -r كان سيأخذ المحتوى الذي نسيته دون كلمة.
3.
What does -f add to rm?
-f إلى rm؟It suppresses the prompts and the errors. Combined with -r it is the most destructive thing you can type, which is exactly why it appears in so many copied commands.
-r يصير أشد ما تستطيع كتابته تدميرًا، وهذا بالضبط سبب ظهوره في كثير من الأوامر المنسوخة.Score / النتيجة: 0 / 3
Your task / مهمتك
Build a small project skeleton from the terminal alone — at least three nested directories and four files — using mkdir -p and touch. Then remove one part of it safely, showing the ls you ran first. Present the whole session as a page, and finish with the rule you will follow before every future rm, in your own words.
ابنِ هيكل مشروع صغير من الطرفية وحدها — ثلاثة مجلدات متداخلة وأربعة ملفات على الأقل — مستخدمًا mkdir -p وtouch. ثم احذف جزءًا منه بأمان، مُظهرًا ls الذي نفّذته أولًا. واعرض الجلسة كلها في صفحة، واختم بالقاعدة التي ستتبعها قبل كل rm مستقبلًا بكلماتك.
- A real session, with mkdir -p and touch جلسة حقيقية فيها mkdir -p وtouch
- The ls you ran before deleting anything الـls الذي نفّذته قبل حذف أي شيء
- A tree or listing of what you ended up with شجرة أو قائمة بما انتهيت إليه
- Your own rule for before every rm قاعدتك أنت لما قبل كل rm