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

pwd

Print the full path of the folder you are in (print working directory).

Niveau
Dagelijks Linux
Groep
Bestanden en mappen
Root nodig
Nee
Pakket
bash (built-in) / coreutils

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

Wat het doet

pwd shows where you are in the tree, from / to the current folder. It is built into Bash; there is also a program /usr/bin/pwd with the same options.

The same value is in the variable $PWD, and the previous folder is in $OLDPWD.

Zo schrijf je het

pwd [-LP]

Opties 4

Meest gebruikt

-L, --logical
Show the path as you entered it, with symbolic links (the default in Bash).
-P, --physical
Show the real path, with all symbolic links resolved.
--help
(Program version) Show help.
--version
(Program version) Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Show where you are

    pwd
    /home/student

    The first command to run when you are lost.

  2. 2Show the real folder behind a link

    cd /etc/alternatives
    cd -P .
    pwd -P

    With links, the logical and the physical path can be different.

  3. 3Use the current folder in a command

    tar -czf /tmp/backup-$(basename "$PWD").tar.gz .

    $PWD is the same as pwd; basename takes the last part.

  4. 4Save the folder and come back later in a script

    HERE=$(pwd); cd /tmp && do_work; cd "$HERE"

    Keeps the script predictable.

  5. 5Check you are in the right place before a delete

    pwd && ls

    A two-second check that prevents deleting the wrong files.

  6. 6Show the previous folder

    echo "$OLDPWD"

    The folder that cd - would take you back to.

  7. 7Print an absolute path of a file in this folder

    echo "$(pwd)/config.yaml"

    Good when a tool needs a full path.

  8. 8See the difference between logical and physical

    ln -s /var/log ~/logs; cd ~/logs; pwd; pwd -P
    /home/student/logs
    /var/log

    The first is the path you used, the second the real place.

  9. 9Show the folder of a process

    pwdx $(pgrep -o sshd)

    pwdx shows the current folder of another process (from /proc/PID/cwd).

  10. 10Use the program instead of the built-in

    /usr/bin/pwd -P

    Same result; useful in other shells.

  11. 11Put the path in the prompt

    PS1='[\u@\h \w]\$ '

    \w in the prompt shows the current folder all the time.

Tips om te onthouden

  • pwd = where am I? pwd -P = where am I really (no links)?

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man pwd