الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

cd

Change the current folder of your shell.

المستوى
امتحان RHCSA
المجموعة
الملفات والمجلدات
يحتاج root
لا
الحزمة
bash (built-in)

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

cd (change directory) moves your shell to another folder. It is built into the shell, because only the shell itself can change its own current folder.

Special targets: cd alone or cd ~ = your home folder, cd - = the previous folder, cd .. = one level up, cd / = the root.

The variable CDPATH can hold a list of base folders that cd also searches.

طريقة الكتابة

cd [-L|[-P [-e]]] [DIRECTORY]

الخيارات 6

الأكثر استخدامًا

DIRECTORY
The folder to go to. Without it: your home folder.
-
Go back to the previous folder (and print its name).
-L
Follow symbolic links logically (the default): pwd shows the link path.
-P
Use the physical folder: resolve symbolic links.
-e
With -P: return an error if the current folder cannot be found.
-@
On systems that support it: show extended attributes as a folder.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Go to a folder

    cd /var/log

    An absolute path works from anywhere.

  2. 2Go back to your home folder

    cd

    Same as cd ~ or cd $HOME.

  3. 3Switch between two folders

    cd /etc/nginx/conf.d
    cd /var/log/nginx
    cd -

    cd - jumps back and forth. Very handy while you edit config and read logs.

  4. 4Go up one or two levels

    cd ..
    cd ../..

    .. is the parent folder.

  5. 5Go to the home folder of another user

    cd ~alice

    Works for root or when you have the rights to that folder.

  6. 6Go to the real folder behind a link

    cd -P /etc/alternatives/java
    pwd

    Shows the real path of the link target.

  7. 7Stop a script when cd fails

    cd /srv/app || exit 1

    Without this check, the next commands (like rm -rf *) would run in the wrong folder.

  8. 8Use the folder of the script itself

    cd "$(dirname "$0")"

    Makes a script work from any place it is called from.

  9. 9Use a short base path list

    export CDPATH=.:/srv/apps:/etc
    cd ssh

    cd ssh now finds /etc/ssh. Put CDPATH in ~/.bashrc if you like it.

  10. 10Remember folders on a stack

    pushd /etc/ssh
    pushd /var/log
    popd

    pushd and popd keep a list of folders. dirs -v shows it.

  11. 11Go to a folder with spaces in its name

    cd "/mnt/backup/Project Files"

    Quotes (or a backslash before the space) keep the name together.

انتبه

  • cd in a script changes only the folder of that script, not of your shell. Use source if you need that.
  • sudo cd /root does not work (cd is a built-in). Use sudo -i and then cd.

نصائح للحفظ

  • cd = home, cd - = back, cd .. = up.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man cd