> For the complete documentation index, see [llms.txt](https://thamizhiniyancs.gitbook.io/cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thamizhiniyancs.gitbook.io/cheatsheets/linux/surfing-knowing-your-file-system/cd.md).

# cd

cd linux command cheatsheet by Thamizhiniyan C S

## Introduction

This command is used to change the current working directory.

***

## Syntax

`cd [-L|[-P [-e]] [-@]] [dir]`

***

## Important Flags

| Flag | Description                                                                               |
| ---- | ----------------------------------------------------------------------------------------- |
| `-L` | Force symbolic links to be followed.                                                      |
| `-P` | Use the physical directory structure without following symbolic links.                    |
| `-e` | Exit with a non-zero status if the current directory can't be determined (when using -P). |
| `-@` | Show a file with extended attributes as a directory containing the attributes.            |

> The default behaviour of the `cd` command is to follow symbolic links, as if `-L' were specified.` ..' is processed by removing the immediately previous pathname component back to a slash or the beginning of DIR.

***

## Examples

<table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd [directory_name]
</code></pre></td><td>Move inside a subdirectory in Linux. Replace `[directory_name]` with the desired directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd /
</code></pre></td><td>Change the directory to the root directory using `/` as an argument.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd ~
</code></pre></td><td>Change the directory to the home directory from any location in the Linux System.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd
</code></pre></td><td>Change back to the default working directory. No arguments needed.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd ..
</code></pre></td><td>Move to the parent directory or one level up from the current directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd [path to directory] &#x26;&#x26; ls
</code></pre></td><td>Change to a new directory and list its contents simultaneously.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd [path to directory]
</code></pre></td><td>Change to a new working directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd -
</code></pre></td><td>Return to the previous working directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd ~[username]
</code></pre></td><td>Change to another user's Home directory.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd 'Directory name with blank spaces'
</code></pre></td><td>Change to a directory with spaces in the name using single quotation marks.</td></tr><tr><td><pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd Directory\ name\ with\ blank\ spaces
</code></pre></td><td>Change to a directory with spaces in the name using backslashes.</td></tr></tbody></table>
