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
cd [directory_name]

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

cd /

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

cd ~

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

cd

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

cd ..

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

cd [path to directory] && ls

Change to a new directory and list its contents simultaneously.

cd [path to directory]

Change to a new working directory.

cd -

Return to the previous working directory.

cd ~[username]

Change to another user's Home directory.

cd 'Directory name with blank spaces'

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

cd Directory\ name\ with\ blank\ spaces

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

Last updated