Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

cd

Change the current folder of your shell.

Niveau
RHCSA-examen
Groep
Bestanden en mappen
Root nodig
Nee
Pakket
bash (built-in)

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

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

Opties 6

Meest gebruikt

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.

Voorbeelden 11

$ als gewone gebruiker# als root (of met 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.

Let op

  • 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.

Tips om te onthouden

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