In this article I'm going to show you how to use the Linux cd command in order to change directories while you are connected to your server via SSH.

Please note in order to follow along with any of these examples, you need to have a VPS (Vitual Private Server) or dedicated server with SSH access. You can read about how to login to your server via SSH for more details.

What is cd?

The cd command stands for change directory, and it's been around for a very long time. Back before computers had nice GUIs (Graphical User Interfaces) to allow us to easily navigate around our file systems, you would need to give the computer commands via command line to let it know where you're trying to go.

A lot of times you might need to connect to your server and move around to different directories in order to locate logs, run a script, or perform various other actions. So becoming very familiar with the capabilites of the cd command can go a long way in making your server management easier.

What can I do with the cd command?

Below I'm going to show the several different ways in which you can use the cd command in order to navigate around your server's file system.

cd

First up is just the cd command all by itself:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]# cd

This will just change directories to the current user's home directory, so this is the output we get:

userna5@vpsXXXX [/home/userna5]#

cd -

Next if we use cd -(tick, or minus symbol), this will take us back to the most recently changed from directory.

userna5@vpsXXXX [/home/userna5]# cd -

So we end up back where we originally started:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]#

cd ~username

If we use cd ~ it will change to the current logged in user's home directory, or if we use cd ~username it will automatically drop us in that specified user's home directory:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]# cd ~userna5

We end up again in our specified user's home directory:

userna5@vpsXXXX [/home/userna5]#

cd directory

When using cd directory this will take us to a sub-directory of the current directory we are in:

userna5@vpsXXXX [/home/userna5/public_html/]# cd wordpress

We end up in the sub-directory wordpress:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]#

cd /directory

When using cd /directory this specifies the absolute directory we are trying to navigate to:

userna5@vpsXXXX [/home/]# cd /home/userna5/public_html/wordpress

We end up back in our wordpress directory, but using a / forward slash this time in front of the directory allows us to jump there from any other directory on the server:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]#

cd ../../

You can use any number of cd ../commands in order to traverse up the directory tree. For example if we use two here:

userna5@vpsXXXX [/home/userna5/public_html/wordpress]# cd ../../

We end up 2 directories up from the directory we were in:

userna5@vpsXXXX [/home/userna5]#

Conclusion

You should now better understand what all you can do with the Linux cd command, as you're trying to navigate around the file system of your server.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!