Command-line skills
CLI A shell is a computer program, which allows users to access the services of an operating system.
A shell interacts with the operating’s system’s kernel via an API.
On the other hand, it’s an interface between us and the kernel, which is the heart of the operating system.
These services include file management, starting/terminating applications, and a lot more.
Shells can be text-based or visual.
A command-line interface such as Command Prompt on Windows and Terminal on Mac, and Bash on most distributions of Linux are examples of shells with a text-based interface.
That’s the program hackers use the most in movies!
As mentioned earlier, a shell is just a program on your operating system, which means you can replace it with a similar one.
Every operating system comes with a pre-installed shell. For instance, Bash is the default shell on most distributions of Linux.
On operating systems that have a windowing system, users usually use graphical shells.
Graphical shells come in the form of a group of loosely coupled programs.
For instance, on Mac, shell consists of Finder, Dock, and Mission Control, to name a few.
On Windows, the start menu and the taskbar are parts of the Windows shell.
However, software developers interact with a text-based shell most of the time.
Here’s an example of a file-management text command in a Linux shell, which streams the content of a file as it keeps changing:
tail -f /var/log/nginx/errors.log
- Install, update, and uninstall a program
- Basic file system operations, such as create, edit, copy, move, and delete files
- Manage the ownership and permissions of files
- Start, stop and restart services
- Read and search through log files
Shell Scripts
Most shells allow users to create special scripts, known as shell scripts.
Shell scripts are computer programs created to run a batch of shell commands automatically instead of running them manually – one by one.
Shell scripts have to be run by the shell.
Here’s an example of a shell script, which prints hello world in the command prompt:
#!/bin/sh # This is a comment! echo Hello World
The statement on the first line (#!/bin/sh) is called a shebang, and means the script should always be run with the defined shell program ( /bin/sh).
/bin/sh is usually a symlink to the system’s default shell program.
Most of the time, you schedule your scripts with a scheduling tool like Cron to run at specific intervals, even when you’re not around.
And sometimes, you set it to run as a one-off task under specific circumstances, such as system failure, etc.
The commands used in a shell script are identical to those you run the command prompt.
However, some shells provide conventional programming features, such as control flow statements (e.g., if, else, and for).
It’s just like you’re writing a program with command-line commands.
With the popularity of cloud-based services and modern app deployment tools, developers only use shell scripts for specific cases.
Remote CLIs
In addition to using your local CLI, you might have to access a remote CLI too.
You usually access a remote CLI from your local CLI over a secured network protocol called Secure Shell (SSH).
SSH is a network protocol, which uses public-key cryptography to do secured network operations over an unsecured network like the Internet.
That said, any command you transmit to the remote CLI (from your local CLI) is encrypted.
On Mac and Linux, you usually use a CLI tool called OpenSSH to connect to a remote CLI.
On Windows, PuTTY is a popular tool to SSH into a remote CLI.
You would use a remote CLI to perform administrative tasks, such as file management, deployments, starting/terminating services, monitoring, and troubleshooting problems.
Never miss a guide like this!
Disclaimer: This post may contain affiliate links. I might receive a commission if a purchase is made. However, it doesn’t change the cost you’ll pay.