Shell Scripting

How to add header and trailer line to a file in Linux

In this article, we will see the different ways to add a header record or a trailer record to a…

Shell Script to print pyramid of Stars

The Basics So here we will print the pyramid of stars in two parts as shown below. We will loop…

Shell/Bash Script to Find Prime Numbers in Linux

A prime number is a whole number that has exactly 2 different factors, 1 and itself. A number that is…

How to convert text files to all upper or lower case

As usual, in Linux, there are more than 1 way to accomplish a task. To convert a file (input.txt) to…

How to write Bubble sort in Bash

Bubble sort is a simple algorithm that basically bubbles up the elements of the array. This means that it traverses…

10 Sed (Stream Editor) Command Examples

Sed is a stream editor in a UNIX-like operating system that is used for filtering and transforming text. Sed is…

Backtick (`) symbol in Linux Shell Scripting

One of the most useful features of shell scripts is the lowly back quote character, usually called the backtick (`)…

How to Find and Delete Empty Directories and Files in Linux

1. Find empty directories in the current directory using find -empty: $ find . -type d -empty 2. Use the…

How to Check if the script is run by root at the start of the script

Check root at start of script Some scripts need to be run as root and you may want to check…

How to Use user-defined Functions in awk

User-Defined Functions You can create user-defined functions in a awk script file using the func or function keywords. Placement in…