Knowledgebase

How to browse directories and list files and directories via SSH

When you access your account through SSH, your current working directory by default is the folder that's named after your master user name. The full path to it would be /home/username, where username is your actual master user name (e.g. /home/john). To see the folders and/or files that are inside a directory you can use the command:

ls

If you execute this command right after you log in, for example, you'll see the subfolders in /home/username (e.g. public_html, logs, private_files). The folder public_html is the one that's used to store contents that can be accessed by web visitors (e.g. your website). To browse through directories and change the current working directory you can use the command cd. To browse to a directory you just have to type the command followed by a space and the path to the particular folder. For example:

cd /home/username/public_html

This will make public_html the current working directory. If the directory to which you want to go is a subdirectory of your current working directory, you don't need to use the full path. For example, your current working directory is /home/username and you want to change it to /home/username/public_html/images. You only have to execute:

cd public_html/images

In this case don't put a forward slash (/) at the beginning of the path.

If the folder to which you want to switch has spaces in its name (or any of the folders in its path), you have to put quotation marks around the name of the folder (e.g. cd /home/username/public_html/"my new folder"/images). In this case it's also possible to put quotation marks around the whole path instead of just around the name of the particular folder.

There are also a few other things that you can do with the cd command. Executing just:

cd

will change the current working directory to the default login folder (/home/username). To move one directory up use the command followed by a space and two dots:

cd ..

To go back to the previous working directory use the command followed by a space and a hyphen:

cd -

The command:

pwd

will show on the screen the full path to the current working directory.

Was this answer helpful?

 Print this Article

Also Read