HomeLinuxUtilizing cd Command in Linux

Utilizing cd Command in Linux


The cd command in Linux is used for altering directories. cd is definitely quick for change directories.

It is one of many important Linux instructions that it’s essential to know.

Utilizing the cd command is kind of easy:

cd path_to_directory

It can’t go any easy than this, can it?

Nevertheless, it is the trail half that you must perceive to simply journey via the filesystem with out getting confused.

Here is a fast recall of absolute and relative paths.

Absolute vs relative path in Linux

And for those who want extra particulars, I like to recommend studying this text.

Absolute vs Relative Path in Linux: What’s the Distinction?

On this important Linux studying chapter, know in regards to the relative and absolute paths in Linux. What’s the distinction between them and which one must you use.

Let’s examine some examples of utilizing the cd command.

Use absolute path to vary the listing

Will probably be simpler to grasp visually. Have a look at the picture under.

Absolute path travel to the python directory
Absolute path journey to the python listing

My present location is my house listing (/house/abhishek) and I’ve to go to the python listing contained in the scripts listing.

As an instance I need to use absolutely the path. Absolutely the path to the pyth/house/abhishek/scripts/python.

cd /house/abhishek/scripts/python
 cd command with absolute path

Use relative path to vary directories

Let’s take the identical instance however this time, I am going to take the relative path.

Relative path example

The relative path to the python listing from my house listing is scripts/python. Let’s use this:

cd scripts/python
cd command with relative path

Go up the listing

To date, you’re going down the ‘stream’. What if it’s important to go up a listing?

As an instance, you’re in /house/abhishek/scripts/python and it’s important to up a listing to scripts?.

Utilizing absolutely the path is all the time an possibility however it’s fairly prolonged. As a substitute, you should use the particular listing notation ... The double dots (..) imply dad or mum listing or up a listing. Single dot (.) means the present listing.

cd ..

Here is an instance:

cd up a directory

You need to use the .. to journey up the trail within the Linux filesystem hierarchy.

Suppose I’m within the python listing within the above picture and need to go to the code listing. Here is what I may do:

cd ../../code
Go up the directory using cd command

Go to the house listing

When you really feel misplaced in all these listing travels and need to return house, there are such a lot of easy shortcuts.

In truth, the best of them is to make use of the cd command with none possibility.

cd

That can take you again to your own home listing from anyplace on the filesystem.

Alternatively, you should use the ~ notation which suggests house listing.

cd ~
Use cd to go back home

Go to the foundation listing

Although you will not use it as typically because the earlier one, it’s nonetheless good to know.

If you wish to return to the foundation listing from the place the filesystem begins, use this:

cd /

There isn’t any ‘magic’ concerned right here. / denotes root when used in the beginning of a path. Do not confuse it with path separators.

Paths in Linux

Change again to the earlier listing

It is a lifesaver or ought to I say timesaver. If you find yourself deep inside a listing construction after which go to a different listing and then you definitely really feel the necessity to return to the earlier location, this shortcut helps.

cd -

Not clear but? Let me present an instance.

I’m within the location /and so forth/apt/sources.checklist.d. From right here, I am going to /house/abhishek/scripts/python to work on my code. After which I spotted that I’ve to verify one thing once more in /and so forth/apt/sources.checklist.d listing.

The standard method could be to do that which makes me kind all the trail once more:

Go back to previous directory

However the good method is to make use of this:

Use cd - to go back to previous directory

See, no have to kind the prolonged path once more. Works marvel!

🏋️ Train time

If you wish to apply the cd command, this is somewhat apply train for you.

  • Open a terminal and go to the /var/log listing. Test the listing contents. What do you see?
  • Now, go to /var listing. That is up a listing.
  • From right here, return to your own home listing.

And that is adequate content material so that you can get aware of the cd command. Listed below are another necessary instructions you must learn about.

31 Primary But Important Ubuntu Instructions

An intensive checklist of important Linux instructions that each Ubuntu person will discover useful of their Linux journey.

Let me know you probably have questions or options.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments