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

FlagDescription

-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

CommandDescription

Move inside a subdirectory in Linux. Replace `[directory_name]` with the desired directory.

Change the directory to the root directory using `/` as an argument.

Change the directory to the home directory from any location in the Linux System.

Change back to the default working directory. No arguments needed.

Move to the parent directory or one level up from the current directory.

Change to a new directory and list its contents simultaneously.

Change to a new working directory.

Return to the previous working directory.

Change to another user's Home directory.

Change to a directory with spaces in the name using single quotation marks.

Change to a directory with spaces in the name using backslashes.

Last updated