05/02/2026
Working with 'for' Loop in Linux!
In Linux Bash scripting, the for loop is used to repeat a set of commands for every item in a list (like a list of files, numbers, or strings).
1. The Basic Syntax: The loop iterates through a list of items, assigning the current item to a variable each time.
for variable in item1 item2 item3; do
# Commands to run
echo "Processing $variable"
done
Key Components:
* variable: A placeholder name (often i, file, or name).
* in: Specifies the list of items to loop through.
* do ... done: The block of code that repeats.
2. Common Examples:
A. Loop Over a List of Strings:
#!/bin/bash
for color in Red Green Blue; do
echo "The color is $color"
done
B. Loop Over a Range of Numbers:
There are two common ways to do this in Bash.
Method 1: Brace Expansion (Easiest)
Best for simple sequences.
for i in {1..5}; do
echo "Number: $i"
done
Method 2: C-Style Syntax
Best if you need custom steps (like increasing by 2) or complex logic.
for (( i=0; i
for i in {1..10}; do
if [ "$i" -eq 5 ]; then
continue # Skip number 5
fi
if [ "$i" -gt 8 ]; then
break # Stop loop after 8
fi
echo "Number: $i"
done
4. The One-Liner: If you are working directly in the terminal, you can write loops on a single line using semicolons:
for i in {1..3}; do echo "Count $i"; done
02/02/2026
Working with If Else Condition in Linux!
In Linux (specifically within the Bash shell), conditional logic allows your scripts to make decisions. The syntax is slightly different from languages like Python or C because it relies on the test command (represented by square brackets [ ]).
1. The Basic Syntax:
The block always starts with if and must end with fi ("if" spelled backward).
if [ condition ]; then
# Code to run if condition is true
else
# Code to run if condition is false
fi
Critical Rule: You must put a space after the opening bracket [ and before the closing bracket ].
* ❌ if [condition] (Will fail)
* ✅ if [ condition ] (Correct)
2. Examples:
Basic if-else (Integer Comparison): This script checks if a variable is greater than 10.
#!/bin/bash
NUMBER=15
if [ "$NUMBER" -gt 10 ]; then
echo "The number is greater than 10."
else
echo "The number is 10 or less."
fi
The if-elif-else (Multiple Conditions): Use elif to check multiple conditions in a sequence.
#!/bin/bash
AGE=18
if [ "$AGE" -lt 13 ]; then
echo "You are a child."
elif [ "$AGE" -lt 20 ]; then
echo "You are a teenager."
else
echo "You are an adult."
fi
3. Comparison Operators:
Bash uses different operators for numbers and text strings.
For Numbers (Integers):
-eq | Equal to
-ne | Not equal to
-gt | Greater than
-lt | Less than
-ge | Greater than or equal to
-le | Less than or equal to
For Strings (Text):
= or == | Equal to
!= | Not equal to
-z | String is empty (null)
-n | String is not empty
4. File Test Operators:
In Linux, you often need to check if a file exists before trying to read it.
FILE="data.txt"
if [ -f "$FILE" ]; then
echo "File exists."
else
echo "File does not exist."
fi
* -f: True if file exists and is a regular file.
* -d: True if file exists and is a directory.
* -e: True if file exists (regardless of type).
* -r: True if file is readable.
* -w: True if file is writable.
* -x: True if file is executable.
28/01/2026
While commands like grep find lines and sed edits them, AWK is a full-blown programming language designed for manipulating data and generating reports.
Think of it as Excel for the command line. It views a text file as a structured table with rows and columns.
1. How AWK Sees Your Data:
By default, AWK assumes that:
* A Record is a line (row).
* A Field is a word separated by whitespace (column).
AWK uses special variables to identify these fields:
* $0: Represents the entire line.
* $1, $2, $3: Represent the first, second, and third columns, and so on.
* NF: A variable for the Number of Fields in the current line.
* NR: A variable for the Number of Records (the line number).
2. Basic Syntax:
The standard way to run an AWK command is:
awk 'pattern { action }' input_file
* Pattern: Tells AWK which lines to look at (like a filter).
* Action: Tells AWK what to do with those lines (usually print).
3. The Power of BEGIN and END
AWK allows you to run code before processing the file and after finishing it. This is great for math:
awk 'BEGIN {sum=0} {sum+=$1} END {print "Total Sum: ", sum}' numbers.txt
* BEGIN: Sets the sum to 0.
* Middle: Adds the value of the first column to sum for every line.
* END: Prints the final total after the last line is read.
24/01/2026
SED is a non-interactive tool used to transform or filter text. Unlike Vi, where you open a file to edit it, sed takes a stream of data (from a file or a pipe), modifies it based on your commands, and spits it back out.
1. The Basic Syntax: The most common use for sed is search and replace. The basic structure looks like this:
sed 's/old_text/new_text/options' filename
* s: The "substitute" command.
* / / /: The delimiters (you can actually use other characters like | or : if your text contains slashes).
* options: Usually g for "global" (replace all occurrences in a line).
2. Key Flags to Remember
* -i (In-place): By default, sed just shows you the result in the terminal. If you want to actually save the changes to the file, use -i.
* Example: sed -i 's/error/success/g' log.txt
* -e (Expression): Allows you to run multiple commands at once.
* Example: sed -e 's/a/A/g' -e 's/b/B/g' file.txt
* -n (Quiet): Suppresses the default output (useful when you only want to print specific lines using the p command).
3. Why Use sed Over Vi?
* Automation: You can use sed in bash scripts to update configuration files without ever opening them.
* Piping: You can take the output of one command and clean it up instantly.
* Example: ls -l | sed 's/root/ADMIN/g' (Replaces "root" with "ADMIN" in your directory listing).
* Massive Files: sed doesn't load the whole file into RAM, so it can process gigabytes of data that might crash a standard text editor.
22/01/2026
The Vi editor is a powerful, text-based editor found on almost every Unix-like system (Linux, macOS).
1. The Three Essential Modes:
To use Vi, you must understand how to switch between these states:
* Command Mode (Default): Every keypress is a command (e.g., deleting a line, saving). You start here.
* Insert Mode: Used for typing text.
* Last Line Mode: Used for saving, quitting, and advanced searches.
2. Basic Navigation (Command Mode):
You don't use the mouse in Vi. While arrow keys usually work in modern versions (Vim), the traditional keys are:
* h (Left)
* j (Down)
* k (Up)
* l (Right)
3. Essential Commands:
Here is a "cheat sheet" for the most common tasks:
Editing:
* x: Delete a single character.
* dd: Delete (cut) the current line.
* yy: Copy (yank) the current line.
* p: Paste the copied/cut text below the cursor.
* u: Undo the last action.
Saving & Quitting (Last Line Mode):
* :w : Save (write) the file.
* :q : Quit (only works if there are no unsaved changes).
* :wq : Save and quit.
* :q! : Quit without saving changes.
Oracle Linux Automation Concepts
12/09/2025
If you don’t like to read, you haven’t found the right book!
10/09/2025
Books are mirrors: You only see in them what you already have inside you!
10/09/2025
Adeptness of Unix & Linux!
The adeptness of Unix and Linux is a cornerstone of modern computing. It's not just about the operating systems themselves, but about the philosophy and ecosystem that surrounds them.
This adeptness can be broken down into several key areas:
1. The Unix Philosophy: The Foundation of Its Power
This is the single most important reason for its success and longevity. It's a set of cultural norms and philosophical approaches to software development. The core tenets are:
- Write programs that do one thing and do it well.
- Write programs to work together.
- Write programs to handle text streams, because that is a universal interface.
This philosophy leads to a system built from small, modular, and incredibly focused tools (like `grep`, `sort`, `awk`, `sed`, `find`) that can be chained together via pipes (`|`) to solve complex problems.
2. Stability and Reliability
Unix and Linux systems are renowned for their uptime. It's not uncommon for servers to run for years without a reboot (outside of kernel updates requiring one).
3. Flexibility and Customization
There is no "one" Linux or Unix. The user has near-total control.
- Choice of Distributions (Linux): From minimalist (Arch, Gentoo) to user-friendly (Ubuntu, Mint) to rock-solid enterprise (Red Hat, SUSE).
- Choice of Components: You can choose your kernel, init system (systemd, OpenRC), desktop environment (GNOME, KDE, XFCE), and every other piece of software.
- Configuration via Text Files: Nearly every aspect of the system is configured through human-readable text files. This makes automation, version control (with Git), and replication trivial.
4. Powerful Command-Line Interface (CLI)
The shell is not an afterthought; it's the heart of the system's power.
- Scripting and Automation: Repetitive tasks can be automated with shell scripts (Bash, Zsh), saving immense amounts of time and reducing human error. This is critical for sysadmins and developers.
- Remote Management: The entire system can be managed efficiently over a network connection using SSH, with no loss of functionality compared to being physically present.
5. Security
The Unix security model is robust and granular.
- User and Group Permissions: The simple but effective read/write/execute permission system for user/group/others.
- Principle of Least Privilege: Users and processes run with only the permissions they absolutely need.
- Auditing and Transparency: Because everything is a file and configurations are text, the system's security posture is auditable and understandable.
6. Open Source Nature (Linux and BSDs)
While not all Unix-like systems are open source (e.g., macOS's Darwin is based on BSD, but macOS itself is proprietary), Linux and the BSDs (FreeBSD, OpenBSD) are. This brings huge advantages.
7. Ubiquity and Portability
The concepts and skills are transferable across a vast landscape.
14/06/2022
Compress a directory, tar -zcvf directory.tar.gz directory
12/06/2022
How to establish passwordless login from one server to another?