Using the Linux cd command

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.


First up is just the cd command all by itself:

[email protected] [/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:

[email protected] [/home/userna5]#

cd –

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

[email protected] [/home/userna5]# cd –

So we end up back where we originally started:

[email protected] [/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:

[email protected] [/home/userna5/public_html/wordpress]# cd ~userna5

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

[email protected] [/home/userna5]#

cd directory

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

[email protected] [/home/userna5/public_html/]# cd wordpress

We end up in the sub-directory wordpress:

[email protected] [/home/userna5/public_html/wordpress]#

cd /directory

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

[email protected] [/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:

[email protected] [/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:

[email protected] [/home/userna5/public_html/wordpress]# cd ../../

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

[email protected] [/home/userna5]#


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.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Let us know!