If you want to learn Linux bash scripting for FREE, open this:
1. What is Shell in Linux
In this guide, let's learn about the shell which is an important part of the Linux operating system which interprets and passes the commands you provide on your keyboard to the operating system to perform some specific tasks
A variable is a named storage location in a program's memory where a value can be stored, retrieved, and manipulated. Like any programming language, Variables are an essential component in the Bash scripts.
In bash, all variables are treated as strings. You cannot perform arithmetic operations on variables as you would normally do in other programming languages since bash interprets them as strings. To overcome this, bash has a built-in tool named let.
Using the let command, you can declare a variable and perform arithmetic operations during the assignment.
As we know bash variables are of string data type, performing arithmetic operations aren’t straightforward. However, bash provides us with several utilities to carry out arithmetic evaluations. One such command line tool is expr.
Using the expr command, you can evaluate any given expression and display the result on the standard output.
We cannot divide numbers directly in Bash as they would be treated as strings. However, Bash provides a lot of tools and commands to perform arithmetic division.
In this guide, we are going to learn about different ways to divide with variables. We will also focus on the advantages and limitations of some of the commonly used methods. Furthermore, we will learn how to round the result of division
The most efficient way to process any file, one line at a time, is to develop a bash script and give the file as input to the script. This can be done by reading a file line by line by iterating the lines over a loop.
Bash treats each line as an element in a list. Understanding how to process the contents of a large data file one line at a time saves us from constantly opening them. There are many ways of reading each line using Bash.
Many times we are only interested in what the remainder is. The mod operator finds use in generating random numbers within a specific range and formatting program output.
It can even be used to generate prime numbers, check if a number is odd or even. Modulo turns up often in the majority of the numerical computations.
In this article, we will learn about the modulus operations in bash.
When it comes to text processing or filtering logs, it becomes important to read the contents line by line. Using the bash while loop you can read the contents one line at a time and use it as per our needs.
We can read from a file, a command and from a variable. We can even read lines into multiple variables.
10. 4 Ways to Check Which Shell You are Using on Linux
Out of the box, Linux provides a wide variety of shells. There is bash (Bourne Again shell) shell which ships by default in many Linux distributions.
We also have sh (Bourne Shell), tcsh (TC shell), csh (C shell), Zsh (Z shell) and ksh (Korn Shell).
Curious to know which shell you are using on your Linux system? In this guide, we explore different ways that you can use to check which shell you are currently using in Linux.
11. Understanding Different Types of Shells in Linux
n the Linux realm, there are multiple shells available, each with its own unique features and capabilities to cater to the varying needs and also preferences of the user.
For instance, the Bourne shell (sh) offers a minimalist set of features for shell scripting, while the Z shell (zsh) offers some advanced ones such as extended globbing and spelling correction.
Therefore, choosing the shell can be subjective based on the task at hand and the specific requirements.
Although it's not necessary to learn all shells, acquiring knowledge on multiple ones can be necessary to improve efficiency....
(one shell for scripting and the other for interactive use) and to increase functionality (taking advantage of the best feature in each shell).
In this tutorial, we will show how to write a shell script to perform a Linux server health check. This script collects system information and status like hostname, kernel version, uptime, CPU, memory, and disk usage.
13. Bash Command Line Chain Operators in Linux with Examples
Linux command chaining is a technique of combining several commands so that each of them can execute after the other based on the operator between them.
The operator that separates these commands is the most important aspect of command line chaining. These operators control how these commands get executed.
To reword, they control the flow of execution. Linux command chaining is very useful if you want to execute multiple commands at one goal.
In Bash, functions do not support returning values like in other programming languages. Instead, the return value of a function is its exit status, a numeric value indicating success or failure. A zero exit status indicates success,
Bash arguments are one of the ways users provide inputs to the executing scripts. Using bash arguments, we create reusable scripts avoiding redundant code.
In this guide, we learn various approaches to passing all arguments in bash scripting.
Any number or string value or list of values (numeric or associative array) can be stored using a variable in bash.
You can define variables in bash without using the `declare` command or by using the `declare` command where the data type is declared at the time of declaration. Bash parameter expansion or parameter expansion is defined by the ‘$’ symbol and the optional curly brackets ({ }).
The parameter expansion is used with the curly brackets when it is required to read or modify the original parameter value. You have to use double quotes (“) when expanding values by using parameter expansion.
This guide explains how you can make use of bash parameter expansion
17. How to Do Bash Variable Substitution (Parameter Substitution)
When the original value of any expression is substituted by another value then it is called substitution. Bash variable substitution or parameter substitution is a very useful feature of bash.
Generally, it is done in the bash by using the '$' character and the optional curly brackets ({}). The content of the bash variable can be checked or modified based on the programming requirements by using variable or parameter substitution.
In this tutorial, we will learn different ways of substituting bash variables.
18. How to Concatenate String Variables in Bash [Join Strings]
Two or more string variables of characters or numbers or a mix of characters and numbers can be concatenated easily in bash. The string variables are required to concatenate for different types of programming tasks.
Many ways exist in bash to concatenate string variables.
In this tutorial, we learn different ways of concatenating string variables in bash.
Bash is a Unix shell and command language that provides users with an interface to the operating system. It is widely used on Linux and other Unix-like operating systems, as well as on Windows using the Windows Subsystem for Linux.
This tutorial will discuss about one of the most useful Bash command, source, which is used to execute commands from a file or script in the current shell environment.
20. Customizing Your Bash Prompt in Linux: Changing Colors
One of the commonly used shell in Linux is bash. Even if there are many modern shells available, it's still the default shell in many Linux distributions.
In this tutorial, we learn how to change the color of specific parts of the bash prompt in Linux. Here we use ANSI escape codes within the PS1 variable.
22. How to Rename Multiple Directories in Linux at Once
To rename a single directory in Linux is simple and straightforward. Whereas to do with multiple directories, we need to use special commands, scripts, or a combination of different commands.
In this tutorial, we learn how to rename multiple directories in Linux at once.
23. All the Ways to Rename Multiple Files in Linux
Linux users may have to rename file frequently and it is very easy to rename a single file. You can just use the mv command to rename one file.
There might also be situations where a user or a Linux system administrator may have to rename multiple files at once. This is a completely different case and Linux supports multiple tools and commands to rename multiple files in one go.
In this tutorial, we learn different utilities to rename multiple files in Linux with examples.
If you want to learn Linux for FREE, open this (a thread of our Linux threads):
1. Permissions
The operating system controls file access in Linux by utilizing file permissions, attributes, and ownership. In Linux, file permissions, attributes, and ownership determine the level of access that system programs and users have to files.
Linux command line tools for parsing and analyzing logs 🐧↓
Linux logs are a valuable resource for system administrators, network administrators, developers, and security professionals.
They record a timeline of events on a Linux system, such as operating system events, application activity, and user activities and actions (for example log-in attempts).
Knowing when and how to stop running processes is an essential skill for sysadmins. When a process becomes stuck, it only takes a gentle nudge to restart or stop it.
At times, a process takes all the system resources. In both cases, you need a cmd that lets you manage a process.
The Linux operating system includes a number of commands for terminating errant processes (rogue processes), such as pkill, kill, and killall.
This thread will teach you how to use the kill command in Linux.
𝗚𝗲𝘁𝘁𝗶𝗻𝗴 𝘁𝗼 𝗸𝗻𝗼𝘄 𝗟𝗶𝗻𝘂𝘅 𝘀𝗶𝗴𝗻𝗮𝗹𝘀
Linux processes use signals to communicate with one another. A process signal is a predefined message that processes can either ignore or respond to. Developers define how a process will handle signals.
In Linux, most people use the ls command to check a file's creation, access, and modification times, ownership, and permissions.
What if I told you there is another great way to display detailed information about files and file systems?
Learn more about it in this thread:
The Linux ls command typically displays basic or chunk of information about a file; however, what if you want to print more information about the file? This is where the stat command comes in.
stat (short for status) is a command-line utility for displaying detailed information about specific files or file systems. It is commonly used to obtain file timestamps.
When writing Bash scripts, you will frequently need to stop the execution of a script when a certain condition is met or perform some actions based on a command's exit code.
In this thread I will go over the built-in bash exit command as well as the exit statuses of the commands that have been executed.