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
-L- Follow symbolic links logically (the default):
pwdshows the link path.
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Go to a folder
cd /var/logAn absolute path works from anywhere.
2Go back to your home folder
cdSame as
cd ~orcd $HOME.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.4Go up one or two levels
cd .. cd ../....is the parent folder.5Go to the home folder of another user
cd ~aliceWorks for root or when you have the rights to that folder.
6Go to the real folder behind a link
cd -P /etc/alternatives/java pwdShows the real path of the link target.
7Stop a script when cd fails
cd /srv/app || exit 1Without this check, the next commands (like
rm -rf *) would run in the wrong folder.8Use the folder of the script itself
cd "$(dirname "$0")"Makes a script work from any place it is called from.
9Use a short base path list
export CDPATH=.:/srv/apps:/etc cd sshcd sshnow finds/etc/ssh. Put CDPATH in~/.bashrcif you like it.10Remember folders on a stack
pushd /etc/ssh pushd /var/log popdpushdandpopdkeep a list of folders.dirs -vshows it.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.
Niets past bij dit filter.
Let op
cdin a script changes only the folder of that script, not of your shell. Usesourceif you need that.sudo cd /rootdoes not work (cdis a built-in). Usesudo -iand thencd.
Tips om te onthouden
cd= home,cd -= back,cd ..= up.