Using The Shell In Linux

In this article, I will explain how to get started using the shell in Linux.

Linux books on Amazon

Using The Shell In Linux 

When people talk about using the command line, they are really referring to the Shell. This is accessed by your terminal window which you run commands in. The shell itself is just a program that works behind the scenes. Almost all distributions of Linux have one included with their version. There are several different versions of Shells also. Some of these are Bash, Zsh, and Fish. 

 

There are also pieces of software called terminal emulators. These small programs help you talk to the Shell. This is something like Konsole or Terminal depending on your distribution. 

 

Your Shell prompt is where you type in commands. If the last character is a ‘$’ then you are a regular user. If the last character is a ‘#’ you are running as a root user which gives you superpowers in the Linux world. 

 

The Shell will give you access to your command history. You see the command history by using the up arrow on your keyboard. Keep pressing the up arrow to see more of your commands you have used. This is useful because you can just use the up arrow to redo commands instead of retyping a long command. Most distributions remember around a thousand of your last commands. 

 

Let’s start using some basic commands. Type the command and then hit enter:

Date

You will see the current time and date pop up.

Now, try the ‘cal’ command:

Cal

You should get a view of the current month. I like to use the ‘cal’ command as I am always forgetting what day it is and it is quicker to use than most other calendar systems. 

Another useful command to use is ‘df’ which tells you how much free space is on your system.

Df

There is a useful parameter you can run with this command and I recommend using it:

Df -h

This makes the output easier to read. I will get into parameters and options later on.

The next command to learn is the ‘free’ command. We will also add the ‘-h’ parameter after it:

Free -h

This output tells you about the memory on your system.

 

Navigating Your File System

The Linux file system looks very different from a Windows file system. It is mainly because everything is named differently. The file system is organized by directories. These directories can contain either files or more directories. In Windows, they are called folders. I will use directories from here on out though. 

 

The first directory in a Linux system is called the ‘root’ directory. It contains everything else on the local system. Linux has a single file system for everything in or attached to that computer. It is important to remember this when navigating. An external storage device is mounted or attached to somewhere in the file system. 

 

To see where you are at any time, use the ‘pwd’ command. This stands for present working directory.

Pwd

It gives a simple one line of output. Mine says:

/home/jason

Whenever we start our computer session in Linux, we start at ‘/home/username’. My username is Jason of course. We can change that later if we want to but that is not important right now. 

 

To see what files are in a directory, we use the ‘ls’ command.

Ls

This command can be used to see the contents of any directory if you know the path. We already know one because we are part of it. It is our ‘home’ directory.

Ls /home

You can also see the contents of the whole computer by looking at the ‘root’. To see the ‘root’, we use ‘/’. So try this:

Ls /

This shows you everything at the ‘root’ level. See the ‘/home’ directory? Your user directory is located within that ‘/home’ directory. Hopefully you can see how your system is organized now. 

 

This brings us to moving directories. We move to a different directory for various reasons. Often, we just want to work from that directory. While we can see what is there by using the path or make a file and put it there, it is easier to just be in that directory. To get to that directory we use the ‘cd’ command:

Cd /home/jason

This is called using an absolute path because we started at the ‘root’ directory denoted by the first ‘/’ and then listed the directory structure until we got to our directory under ‘/home’.  We can also use relative pathnames. It is called this because it is relative to our present directory. So:

Cd ..

Will move us up one directory from our present working directory. 

‘Cd’ is a very helpful command. It allows for fast movement if you use a few tricks.

To instantly go to your ‘/home’ directory:

Cd

To change the working directory to the previous directory:

Cd -