Shell navigations basics

Shell navigations basics

The name shell was given because it is the outermost layer of the operating system (OS).


Chinonso John Nkpolukwu

John Nkpolukwu

Last month

What is a shell?

A shell is a command line interpreter that allows users to communicate efficiently and directly with their operating systems (OS), giving them control over their computer.

The name shell was given because it is the outermost layer of the operating system (OS). It sits between the command line interface (aka the terminal) and the operating system (OS) processing CLI commands before sending them to the operating system OS.

The terminal is also known as the command line

The shell has two categories, Command line shell and Graphical Shell.

Command line shell

A command-line shell provides an interface that allows users to control their operating system through the command-line interface (CLI). Users enter commands into the CLI, which the shell interprets and then passes to the OS for execution. Once the command is executed, the output is displayed to the user via CLI.

Z shell (also known as zsh) a Unix shell built on top of the default bash shell of macOS

Graphical shell

The graphical shell similar to the command-line shell allows users the same control over their operating system OS. This is done through a graphical user interface aka the GUI. The user uses their mouse to navigate to and click on actions that lead to commands for Shell to interpret and process.

An example of this is the start menu on the Windows OS or the finder menu on the MacOS.

The simplicity of macOS Graphical User Interface (GUI)

Windows 10 operating system menu Graphical User Interface (GUI)

The importance of the Shell

The shell simplifies the interaction between the user via the command line and the Operating System which only understands machine code.

Rather than writing machine code directly from the command line which is inefficient and time-consuming due to its complexity, we use higher-level languages and commands.

The Shell is important because it allows us to enter human-readable code and commands into the command line which it then interprets and translates into system calls or instructions that the Operating System (OS) can execute.

These commands often trigger pre-compiled programs or binary executables, which handle the lower-level machine code interactions with the OS.

<details> <summary>Why don’t we send commands directly from the terminal to the operating system OS, skipping the shell?</summary>

We don't write commands directly from the terminal to the OS because the OS only understands machine code and writing machine code is inefficient, time-consuming, and error-prine due to its complexity.

Rather than writing machine code directly from the command line, we use higher-level languages and commands.

The Shell is crucial because it allows us to enter human readable code and commands in the command line which it then interprets and translates into system calls or instructions that the Operating System (OS) can execute.

These commands often trigger pre-compiled programs or binary executables, which handle the lower-level machine code interactions with the OS.

</details> ### Control flow:

User interacting with the OS via the Terminal (Command Line)

Terminal → Shell → Program [ OS (Userspace) → Kernel (Core OS) → Hardware ]

  1. Terminal – A text-based interface where users enter commands or inputs, which are then passed to the shell for processing.
  2. Shell – Interprets and processes commands from the terminal. It interacts with the operating system by making system calls to request services from the kernel.
  3. Operating System Kernel – The kernel is the core part of the OS. It handles system calls from the shell or other programs and manages the system's hardware resources, like memory, CPU, and I/O devices, by interacting directly with the hardware.

Simple shell commands

#How to navigate in a Unix system

cd [directory name] -> to change directory
cd .. -> go back to the previous directory
cd - -> toggle back and fourth to the most recent directory


#How to list files and directories
 
ls -> list all files and directories in the current directory


#How to display the content of a file

cat [filename]
less [filename]
 

How to navigate in a Unix system

```javascript
cd [directory name] -> to change directory
cd .. -> go back to the previous directory
cd - -> toggle back and fourth to the most recent directory 
```

How to list files and directories

```javascript
ls -> list all files and directories in the current directory
```

How to display the content of a file

```javascript
cat [filename]
less [filename]
```

How to create a file or directory

```javascript
touch [file name] -> creates a file
mkdir [directory name] -> creates directory 
```

How to remove a file or directory

```javascript
rm -rf -> removes a file
rm -> removes directory
```

How to move or copy a file or directory

```javascript
mv [filename] [/path/to/move/to] -> move a file to a directory
cp [filename] [/path/to/move/to] -> copy a file to a directory
```

Conclusion

The shell serves as a common thread across all programming languages, simplifying complex commands into concise, intuitive instructions. Mastering the shell is a crucial skill for any data scientist or computer engineer.

Shell FAQ's

<details> <summary>What is the kernel?</summary>

The kernel is the most essential part of the operating system. The kernel is responsible for allocating memory and time to the computer’s programs, and it manages the communications and filestore in response to system calls.

</details><details> <summary>What is the Shell?</summary>

The shell is the interface between the kernel and the user.

</details><details> <summary>What is an interpreter? </summary>

An interpreter interprets single statements into machine code.

</details><details> <summary>What is a compiler</summary>

A compiler translates high-level programs into more complex machine language.

</details>