DEV Community

Cover image for Shell Navigations for Beginners
sahra 💫
sahra 💫

Posted on • Edited on • Originally published at dev.to

Shell Navigations for Beginners

Shell navigations is all about being able to navigate the shell through a series of in-built commands that are used to perform various tasks.

What is a Shell?

A shell is a computer program that serves as an interface which allows for direct interaction with the computer's operating system.

It can be referrenced to an actual real life shell in the sense that what it does is it acts as the outermost layer of the operating system, just right after the kernel.

operating system hierarchy

In this article i would be focusing only on the Bash UNIX/Linux shell.

What is Bash?

This is a command line interpreter based of the UNIX(UNiplexed Information Computing System) operating system.

This is one on the most commonly used shells out there.

There are also other shells available as well like: zshell, Cshell, KornShell, powershell etc.

What it basically does, is that It reads commands typed in by the user and executes programs based on those commands. When a program finishes executing, it displays a new prompt to signify that it is ready to take in another command as it's done executing the previous one.

There are a set of in-built commands, that are used to communicate differenly with the operating system, and we are going to look at a few of the most basic of them that you are going to be needing quite often the more you interact with the shell.

10 Basic Bash commands

  • ls

stands for: (list)

This command is used to list out contents of a directory.

typical usage and sample output:

$ ls

file1 f1le2
file3 file4
Enter fullscreen mode Exit fullscreen mode
  • pwd

stands for: (print working directory)

This command is used to print out the current directory you're in.

typical usage and sample output:

$ pwd

/root/home
Enter fullscreen mode Exit fullscreen mode
  • cd

stands for: (change directory)

This command is used to change from the current directory you're in to another directory.

typical usage and sample output:

$ cd demoDirectory

demoDirectory $ 
Enter fullscreen mode Exit fullscreen mode
  • mkdir

stands for: (make directory)

This command is used to create a new directory.

typical usage and sample output:

$ mkdir newDirectory

Enter fullscreen mode Exit fullscreen mode
  • cat

stands for:(concatenate)

This command is used to print unto the standard output the contents of the file specified.

typical usage and sample output:

$ cat file1

I am the content of file1.
Enter fullscreen mode Exit fullscreen mode
  • rm

stands for: (re move)

This command is used to remove (delete) files from a directory.

typical usage and sample output:

$ rm file1

Enter fullscreen mode Exit fullscreen mode
  • touch

stands for: (touch)🤷‍♀️
This command is used to create, change and modify timestamps of a file.
But it is most commonly used to create a new file that does not already exists.

typical usage and sample output:

$ touch newfile

Enter fullscreen mode Exit fullscreen mode
  • echo

stands for: (echo)🤷‍♀️

This command is used to write a string to a file. If a file is not specified, it writes to the standard output by default.

typical usage and sample output:

$ echo "hello world"

hello world 
Enter fullscreen mode Exit fullscreen mode

Writing to a file.

$ echo "hello world" > file1

Enter fullscreen mode Exit fullscreen mode

Now file1 contains the string

hello world

It can also be used to print out the value of an environment variable.

$ echo $variableName

value of variableName
Enter fullscreen mode Exit fullscreen mode
  • mv

stands for: (move)

This command is used to change the name of a file from one name to another.
It can also be used to move a file from one directory to another.

typical usage and sample output:

$ mv file1 file2
Enter fullscreen mode Exit fullscreen mode

This has renamed the file file1 to now become file2.

moving a file from one directory to another:

$ mv file1 someDirectory
Enter fullscreen mode Exit fullscreen mode

This has moved the file file1 from the current directory to a directory called someDirectory.

  • whoami

stands for: (who am i)

This command is used to print out the name of the current user of the shell.

typical usage and sample output:

$ whoami

username1
Enter fullscreen mode Exit fullscreen mode

Basic Exercise

Let have a look at a very basic exercise.

For instance let's say we want to change our working directory to the /root directory, then create an empty file called so_cool in that directory.
All you have to do is:

$ cd /root
Enter fullscreen mode Exit fullscreen mode

Now we are in our root directory, so let's create our new empty file now.

$ touch so_cool
Enter fullscreen mode Exit fullscreen mode

This has created our file.
To check out if the file was created, you can simply just run the ls command to display the list of files in the root directory, your newly created file should be among.😊

There a still a whole number of bash commands out there that are used to perform various other tasks, but we can't cover them all.

That's it for this article guys...if you found it helpful, please don't forget to leave a like and also, don't forget to follow me for more content... see you next time 😊😊♥️

Top comments (6)

Collapse
 
_kithinjibrian profile image
Kithinji

thank you

Collapse
 
tundeazeez profile image
TundeAzeez

Amazing and quite clear
Thank you

Collapse
 
blackpytz profile image
Blackpytz

Why doesn't this post have a million more likes?

Collapse
 
sarahokolo profile image
sahra 💫

Thanks reid... u're awesome 😊

Collapse
 
rawan22hossam profile image
Rawan Hossam Mohammed

Good Bless you Thank you really for your help Keep going

Collapse
 
sarahokolo profile image
sahra 💫

You are very welcome 😊. Thanks