2023-07-05 10:53:12 +02:00
|
|
|
# The cd builtin command
|
|
|
|
|
|
|
|
## Synopsis
|
|
|
|
|
|
|
|
cd [-L|-P] [DIRECTORY]
|
|
|
|
|
|
|
|
cd -
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
The `cd` builtin command is used to change the current working directory
|
|
|
|
|
|
|
|
- to the given directory (`cd DIRECTORY`)
|
|
|
|
- to the previous working directory (`cd -`) as saved in the
|
2024-01-29 02:07:56 +01:00
|
|
|
[OLDPWD](../../syntax/shellvars.md#OLDPWD) shell variable
|
2024-03-30 19:22:45 +01:00
|
|
|
- to the user's home directory as specified in the
|
2024-01-29 02:07:56 +01:00
|
|
|
[HOME](../../syntax/shellvars.md#HOME) environment variable (when used
|
2023-07-05 10:53:12 +02:00
|
|
|
without a `DIRECTORY` argument)
|
|
|
|
|
|
|
|
The `cd` builtin command searches the directories listed in
|
2024-01-29 02:07:56 +01:00
|
|
|
[CDPATH](../../syntax/shellvars.md#CDPATH) for a matching directory.
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
The default behaviour is to follow symbolic links unless the `-P` option
|
|
|
|
is given or the shell is configured to do so (see the `-P` option of
|
2024-01-29 02:07:56 +01:00
|
|
|
[the set builtin command](../../commands/builtin/set.md)).
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
### Options
|
|
|
|
|
2024-10-19 00:57:25 +02:00
|
|
|
|Option|Description|
|
|
|
|
|------|-----------|
|
|
|
|
|`-L`|Follow symbolic links (default)|
|
|
|
|
|`-P`|Do not follow symbolic links|
|
|
|
|
|`-@`|Browse a file's extended attributed, if supported|
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
### Exit status
|
|
|
|
|
|
|
|
- true if the directory was changed successfully
|
|
|
|
- false if a change to the home directory was requested, but
|
2024-01-29 02:07:56 +01:00
|
|
|
[HOME](../../syntax/shellvars.md#HOME) is unset
|
2023-07-05 10:53:12 +02:00
|
|
|
- false if anything else goes wrong
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2024-03-30 19:22:45 +01:00
|
|
|
### Change the working directory to the user's home directory
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
cd
|
|
|
|
|
|
|
|
### Change the working directory to the previous directory
|
|
|
|
|
|
|
|
cd -
|
|
|
|
|
|
|
|
## Portability considerations
|
|
|
|
|
|
|
|
## See also
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- variable [CDPATH](../../syntax/shellvars.md#CDPATH)
|
|
|
|
- variable [HOME](../../syntax/shellvars.md#HOME)
|
|
|
|
- variable [OLDPWD](../../syntax/shellvars.md#OLDPWD)
|
|
|
|
- the `-P` option of [the set builtin command](../../commands/builtin/set.md)
|