Cd Command in Linux Terminal with examples

Cd Command in Linux Terminal with examples

In this article we are going to shows how to use cd command in Linux Terminal. If you want to learn about cd command in Linux with Examples then this post is ideal for you.

The cd is a command-line shell command that is used to change the current working directory in Linux operating systems. It can be used in shell scripts and batch files.

A directory where you are currently working in, is know as Current Working Directory. When you log in to your system then your current working directory is home directory. 

Linux is an operating system, like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).

Linux OS(operating system) is also distributed under an open source license. Open source following these points :

  • Freely to run the program, for any purpose.
  • Free to study how the program works.
  • Freely to re-distribute copies so you can help your friends.
  • Free to distribute copies of your modified versions to others.

cd Command in Linux

In the Linux, the basic syntax of the cd command is show as below:

$ cd [OPTIONS] directory

The cd command accepts only two options, are listed below:

  • −L– it is follow symbolic links. By default, cd command behaves as if -L option is specified.
  • −P – It don’t follow symbolic links.

When you run the cd command without any option and argument, it will take you to your home directory.


Examples of cd command

Change directory to the root directory

Run the below command to change directory to the root directory:

$ cd /

Move inside a directory from a director

Run the below command to move inside a directory from a director:

$ cd dirname_1/dirname_2/dirname_3
$ cd Documents/studiesonline/examples

Change directory to the home directory

Run the below command to change directory to the home directory:

$ cd ~

or

$ cd 

Move to the parent directory of current directory

Run the below command to move to the parent directory of current directory(one level up from the current directory):

$ cd .. 

Navigate to the Previous Directory

Run the below command for navigate to the previous directory:

$ cd -

Navigate to a directory with Space in their Names

$ cd "directory name"

or

$ cd 'directory name'

or

$ cd directory\ name

That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top