Shell and Navigation

Getting started with the linux terminal or command line for windows can be frightening sometimes especially to regular users - those that are not well-versed with computer systems, feeling like they have to abandon all the knowledge they have acquired so far in operating their systems and starting anew with a clean slate. I agree it's scary at first but you get the hang of it as time goes on. Well, you are definitely here because you and the terminal have found a common ground to start a relationship. I hope your new found partner will last. Without further ado, let's get into some action.

What is a Shell?

A shell is just a computer program that bridge the gap between a computer operating system and the user. It takes in command received from the keyboard and give it to the operating system to handle and process. The first shell developed by Ken Thompson was originally built for the Unix operating system and new versions was released from 1971 to 1975. Most variations of shell today are based off of this original shell. These include: ksh, tcsh and zsh.

The shell, sh, was the old way one could interact with computer before the birth of graphical user interface (GUI). You might have also heard of Bash, it stands for Bourne Again SHell. It's an enhanced version of the original unix shell written by Stephen Richard Bourne ("Steve Bourne").

What is a Terminal?

A terminal or terminal emulator is basically an application that opens up a window where you can interact with the shell and perform various commands as you deem fit. It is called a terminal on linux or unix-like systems and command line on windows

Who likes story?...Let's get this thing started already.

We will be taking a look at some of the commands you will use to navigate around your directories. The first being pwd, followed by ls and cd

  • pwd: This stands for print working directory. Imagine walking inside a maze and suddenly, you get lost and there is nothing to help you out at the moment except lingering to the hope that you will eventually come out but that will cost you time and efforts before that happens. Just imagine there is something you could call upon to tell you where you currently are and where you have been, cool, right?. pwd does that for us in the context of command line interface. When used, it print out the path you took to get to where you are, so you can retrace your steps.
[me@linuxbox me]$ pwd 
/home/me
  • ls: Use this command to see what you have in your current working directory. When the shell receive this command from the keyboard and pass it to the OS (operating system). The OS then prints out all the folders and files in this current directory except the hidden files and folders. We will take a look on how to go about including those files too of course but first let's see how this bad boy works
[me@linuxbox me]$ ls
Desktop    Downloads         foo.txt  Pictures  Templates
Documents  examples.desktop  Music    Public    Videos
  • cd: We have seen how to list out all the contents inside a folder/directory as well as knowing the current working directory we are in. The next on the list is navigating around these pool of folders of ours. The magic word is cd (change directory), there is no telling the kind of havoc this could bring if this command get into the wrong hands, the safety and integrity of your files depends on it.

We type cd followed by the desired pathname. A pathname is the route or location of the directory/file through which the command will use in getting us to the specific directory/file we want. There are two types of pathname: one is absolute and the other is relative.

An absolute path is the path that always begins with the root folder i.e the directory that holds all other directories and files. For example, the picture below shows a typical unix-like file system structure, let's assume we are given a task to check what is inside the user1 directory. We start with cd then the full path to the location you want to go, like cd /home/user1. The leading slash represent the root folder, this means from the root folder, go to home directory and enter user1 directory. Without further ado, let's take this bad boy for a test run...

Linux-Directory-Structure.png

[me@linuxbox me]$ cd /home/user1
[me@linuxbox me]$ pwd
/home/user1
[me@linuxbox me]$ ls
Desktop  Documents  Music

while absolute takes on the full pathname of the directory/file you want to get to, a relative path only need the pathname starting from the current directory you are in. A relative path uses two weapons to achieve this great mission. It uses "." and ".." to traverse the directories in a short and concise manner. The single dot here represents the current working directory itself while the double dots represent the current working directory's parent directory. Remember the last command we look into take us inside the user1 folder. Now let's say we wanted to navigate to the Documents folder, we do this by typing cd ./Documents:

[me@linuxbox me]$ cd ./Documents
[me@linuxbox me]$ pwd
/home/user1/Documents

What if we decided to move back one step, then we type: cd .. But let's first ascertain where we are in the file trees using pwd

[me@linuxbox me]$ pwd
/home/user1/Documents 
[me@linuxbox me]$ cd ..
[me@linuxbox me]$ pwd
/home/user1
[me@linuxbox me]$ ls
Desktop  Documents  Music

That's the end of the today's episode in teaching myself new things. Gracias