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:
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:
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:
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:
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:
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:
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:
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.
We value your feedback!
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.
Post a Comment
Do you want to publish a tutorial to our support center?