Linux Command Line for beginners – File Navigation

I was a youngster in a time when there wasn’t much more than typed commands to control a computer. In 1982, when I was 12 years old, I bought my first computer, the Commodore 64. At the time, this was the dream of every nerdy teenager and soon I was able to use various text commands to smoothly maneuver through this exciting new computer world. Years later I bought my first real personal computer, powered by MS-DOS 5.0, again a command line powered interface, to control my computer. If you do not know any other alternative, using the command line is logical and therefore may be relatively easy to learn. But if you switch to a graphical interface years later and you use your mouse, or later touch control, to control your devices, then using typed commands is no longer that logical anymore and for most people not their first choice. After first working with Windows 3.1, then Windows 95 and Windows XP and after that OS X and macOS for more than 10 years, my expertise with and knowledge of using text commands became a lost skill. But when a few years ago I got very interested in Linux and started to learn a lot about it from the Linux community, I was initially surprised that a lot of people talked about the command line with passion. But for Linux there are so many beautiful graphical desktop environments, why did people speak so passionately about the command line? Later I learned that in Linux the command line is a very powerful way to perform a large number of tasks in a very effective way and some tasks can’t just be done in a graphical manner. In this article, which is part of my planned “Linux command line for beginners” series, we will look at File Navigation.

Introduction

Those who regularly visit my website www.RealLinuxUser.com will often read that I very much prefer the graphical interface instead of using the command line. First of all I am personally very graphically oriented so working in a graphical way feels more natural to me. But also my website is aimed at beginning Linux users and users who are more interested in using Linux for productive purposes than that they are interested in the deep-set technology behind the system. So in my opinion, when I want to promote Linux within this target group, in which users have probably more experience with other graphics based user interfaces, it is the most logical if I do that by writing articles that are primarily focused on working with the graphical interface. So now you probably wonder why I intend to write a whole series of articles about the use of typed commands. As indicated above, a number of tasks can be performed much simpler or faster with text based commands and even some activities can’t be done without the help of the command line. I’m not saying that now you immediately have to start only using the command line. It’s just useful to understand something about using the command line, so you can use it in the right situations. And at least it will help to just to better understand many articles of other bloggers or understand the answers when you are asking questions or search for information on Linux forums.

In this article, I will focus on navigation via the command line. At the end of this article, you will have a basic understanding of how to browse through your folder structure in an effective manner. In a separate article, we will focus more on creating, moving, and deleting folders. So let’s begin.

Note: Before we begin, I would like to point out a nice command line reference to fall back on, written by Hitesh Jethva from the website PCWDLD.com. In this cheat sheet, he brings together a useful overview of the most commonly used Linux commands to help you to perform your day-to-day system administration task.

Linux commands cheat sheet – PCWDLD.com

Something about folder structure

First, let’s create a framework within which we want to place this navigation tutorial. With every clean installation of Linux, a large number of folders and files are installed on your system. An important group of folders and files are located in a structure under the /home folder. In the /home folder there is a main folder for every user created. In my case that is /johnbeen.

My and your home folder contains our user specific data files and user specific configuration files. Linux is all about security so every individual user has its own account on your system and only has access to its own home folder. If you need to have extended access rights than you must do via the Root user. But that will be something for another tutorial.

When we look at the hierarchy in this structure, my personal folder is directly situated under the /home folder in the following way: /home/johnbeen. Multiple subfolders can then be found under my personal folder. This can, for example, have the following structure:

The /home folder itself is also a sub folder under what we call the Root directory which is indicated with just a “/”. So /home is the next level below the main level or root level “/”. In addition to the folder /home there are many more folders below the root level. Do you want to know more about the meaning of those folders then read my earlier article “Simple explanation of the Linux file structure“.

For this article, as already indicated, we are going to focus on the topic of navigation and we do that as an example within our own /home directory and all underlying folders.

Navigation via the command line

Now let’s start with starting up a CLI, or a Command Line Interface or also called the Terminal. Within most distributions you can start the Terminal with the key combination Ctrl + Alt + T.

First, let’s look at what the Terminal initially shows. In the example above we see:

johnbeen@JBi7LinuxWS001:~$

First we see the login name. Next to that you see the name of the computer. So in my case it says user = johnbeen at computer = JBi7LinuxWS001.

Next we can see the following symbol: ~. This symbol is called the “tilde” and is an abbreviation to indicate the complete path to your home folder, in my case /home/johnbeen.

Finally we see a dollar sign. A dollar sign ($) means you are in normal user mode. When you see a hash sign (#) it means you are the system administrator (root) mode.

Now let’s start typing some Linux commands.

Command: pwd

The “pwd” command, which stands for “Print Working Directory”, is very useful to simply see where you currently are in the file structure by presenting the complete file structure.

So type the following command and hit Enter:

pwd

When we start the Terminal we always automatically are positioned in our personal home folder, so in my situation I will see something that looks like the following output:

/home/johnbeen

But say that you are for example in your Pictures folder, then the pwd command should give you the following result:

/home/johnbeen/Pictures

Command: cd

The cd command stands for Change Directory and does exactly what the name implies. Type for example the following command and give Enter:

cd Pictures

When you typed the command correctly, you will see something like:

johnbeen@JBi7LinuxWS001:~/Pictures$

Note: folder and file names in Linux are case sensitive, so if you typed pictures instead of Pictures, then you will get a message that says something like “bash: cd: pictures: No such file or directory”.

Remember that I said that the tilde represents your home directory. Type the following command to check that this is really the case:

pwd

The result will be in my situation:

/home/johnbeen/Pictures

It was possible to go directly to this folder by using the command “cd Pictures” because this folder is one of the subfolders in the folder that I was positioned in at that moment. We call this a movement based on a relative path, which means that it is not necessary to type the complete path starting from the root for sub folders in the folder that you are currently in. In the following section we will discuss a change of location based on an absolute path.

Go directly to a specific folder

In the previous section I mentioned using relative paths. Relative paths are always relative to your current position. But it is also possible to go directly to a location from whatever position you are currently in. This is called a movement based on an absolute path.

Say for example that I am in the folder /mnt and I want to go directly to go to /home/johnbeen/Videos, then I can’t use the command cd Videos, because the Videos folder is not positioned in the mnt folder, as it is in a different branch seen from the root folder. Instead type the following command:

cd /home/johnbeen/Videos

So based on the cd command combined with an absolute path you go directly to a specific folder independently of where you currently are.

Remember the tilde symbol? You can also use the tilde symbol to go to another branch in your folder structure as part of your home directory. For example if I am currently in /home/johnbeen/Videos/2019 and I want directly go to /home/johnbeen/Pictures/Landscapes/2018, then I can use the following command:

cd ~/Pictures/Landscapes/2018

Go directly to your home folder

To navigate from whatever location in your folder structure directly to your home folder you can type one of the following commands and hit Enter:

cd

cd ~

Go directly to the root level

When you want to move from whatever location in your folder structure directly to the root directory you can type the following command and hit Enter:

cd /

Move up one level

From your current position in the directory structure you can simply go up one level by typing the following command:

cd ..

For example when I am currently in /home/johnbeen/Videos and I type cd .., then I will go back to /home/johnbeen/.

Navigate to the previous level

When you were busy navigating based on absolute paths or relative paths, you may be want to jump directly from your current position to the previous position where ever that was. You don’t have to remember that specific location because all you have to do is type the following command:

cd –

So as an example, say that I previously manoeuvred from /home/johnbeen/Document/Administration/Bank/Scans/2019 to /Media. If I want to go back to where I came from, I don’t want to remember and type the complete path /home/johnbeen/Document/Administration/Bank/Scans/2019 again. By just typing cd – I will jump back one step in time to my previous location.

Command: ls

Now that we know a little on how to navigate in the folder hierarchy, you probably like to see what is actually in a specific folder. To do that type the following command and hit Enter:

ls

The command “ls” stands for List and gives you an overview of all files and folders in the current directory. For example, when I am in my home folder, then the ls command gives me the following result:

In this picture you see that the files and folders are presented in columns. But what if you want to present the results in a row. Then type the following:

ls -x

Or what if you want to have a nice list of your files and folders each one on a separate row and maybe see some extra information? Just type the following command:

ls -l

Now you will get all items separated per row with extra information on permissions, owner, file size and modification date.

If you want to learn more about all the options that can be used in combination with ls, type the following:

ls –help

If you want to open the manual on the ls command just type the following:

man ls

You can use the ls command also in combination with the relative and absolute folder structure, like you did with the cd command. So say that I am in /home/johnbeen and I want to see the files and folders in the Pictures folder without first navigating to the Pictures folder, then I type the following command:

ls /home/johnbeen/Pictures

or even shorter:

ls ~/Pictures

It is also possible to combine the content of multiple directories by adding the directory paths separated by a space after the ls command, for example:

ls /home/johnbeen/Documents /home/johnbeen/Videos /home/johnbeen/Pictures

This will give you a combined list of all the files and folders in these 3 folders.

Final words

Ok. We reached the end of this tutorial on navigating via the command line. I hope you have enough information and some basic understanding to do some simple navigation on your own. Probably you think now that we could do most of the above also with a file manager with a graphical user interface. And of course you are right. But I hope you can see that for example combining multiple directory structures in an ls command that results in a complete list of the content of all these directories, is something you can’t do with the standard graphical file managers. Next to that you should see this tutorial as a step up or a foundation for more complex activities that we can do with terminal related commands . At the end of the complete course you will be able to combine terminal commands to do navigation, create, copy, move and delete folders and files and do even far more complex stuff.

To be continued…

User Avatar

About John Been

Hi there! My name is John Been. At the moment I work as a senior solution engineer for a large financial institution, but in my free time, I am the owner of RealAppUser.com, RealLinuxUser.com, and author of my first book "Linux for the rest of us". I have a broad insight and user experience in everything related to information technology and I believe I can communicate about it with some fun and knowledge and skills.

View all posts by John Been →