Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567



How the CD Command Works in Linux

The cd command in Linux stands for change directory and is used to change directory when you have a terminal window open. It’s used frequently, so it is useful to know.

The syntax for the cd command looks like this:

How the CD Command Works

At its most basic, when we open a new terminal window, we can use cd to navigate between directories. Suppose we are in Documents, and there is a subfolder called Project. If we want to move into the Project folder, we would type the following:

And if we want to move back up to documents, we can use ../ – so assuming we are now in Project, the following command will bring us back to the Documents directory:

Using Relative Path Names With CD in Linux

While ../ refers to the directory one level above, ./ refers to the current directory. As such, if we are in Documents and want to move to Project again, the following command will also work:

We can also string ../ together – so the following will move two directories up:

How To Navigate to the Home Directory in Linux

If you want to navigate to the home directory in Linux, we have to use the cd command along with a tilde, or ~.

As such, the following command will navigate us to the home directory:

We can also navigate to directories within the home directory by following it with a slash, so the following will move us into a folder called Project within our home directory:

Options for the CD Command in Linux

There are two options available to the cd command which we can mention straight after we type cd. These are:

  • -L – which is by default enabled, and ensures recognition of symlinks within Linux.
  • -P – which does the opposite of -L and ignores symlinks.

What Are Symlinks?

Symlinks or symbolic links are virtual folders. They link to other folders in other directories. If we use -P with cd, then symlinks are ignored.

An example of a cd command with symlinks disabled looks like this:

Credit: Source link

Previous Next
Test Caption
Test Description goes like this