Menu

Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

29 Oct 2025

🐧 Linux Shell Scripting for Beginners – Part 1: What is a Variable?πŸ’»

Welcome to this Shell Scripting series! In this first part, we will learn about variables in a very simple and easy-to-understand way.

πŸ“‘ Table of Contents



🌟 What is a Variable?

A variable is like a small box where you store some information. Later, you can open the box and use that information again in your script.

✏️ How to Create a Variable

name="Pradeep"
course="Shell Scripting"
count=10

Important: There should be no space before or after the = sign.

❌ Wrong

name = "Pradeep"

✅ Correct

name="Pradeep"

πŸ“’ How to Use a Variable

echo "Hello $name, welcome to $course training!"
Hello Pradeep, welcome to Shell Scripting training!

🧊 Variables That Cannot Change (readonly)

readonly company="MiddlewareBox"

If you try to change it again, the script will not allow it.


🌍 Global and Local Variables

name="Pradeep"   # Global variable

greet() {
  local name="DevOps Engineer"
  echo "Inside function: $name"
}

greet
echo "Outside function: $name"
Inside function: DevOps Engineer
Outside function: Pradeep

🧠 Store Command Output in a Variable

today=$(date)
echo "Today is: $today"

πŸ’» Simple Practical Example: System Info

host=$(hostname)
os=$(uname -s)
kernel=$(uname -r)

echo "Hostname: $host"
echo "OS: $os"
echo "Kernel: $kernel"

πŸš€ Simple Use Case: App Deployment Path

app="orderservice"
version="v2.3"
path="/opt/apps/$app"

echo "Deploying $app version $version"
mkdir -p $path
cp $app-$version.jar $path/


🧡 Multi-Word Values (Use Quotes)

msg="Hello Shell Scripting Learners"
echo "$msg"

πŸ” Use Variables as Counters

count=1

while [ $count -le 3 ]; do
  echo "Count: $count"
  count=$((count+1))
done

❓ Check if a Variable is Empty

if [ -z "$name" ]; then
  echo "Name is empty"
else
  echo "Name is $name"
fi

⏱️ Use Time in Variable (Backup File Name)

time=$(date +%Y-%m-%d_%H-%M-%S)
file="backup_$time.tar.gz"
echo "Backup file name: $file"

🧰 Small Real-Life Script: Create User and Log

username="john"
log="/var/log/user_creation.log"

echo "Creating user: $username" | tee -a $log
useradd $username
echo "User $username created at $(date)" | tee -a $log

πŸ‘ Quick Summary

TopicMeaning
VariableA box to store data
$variableUse the value
readonlyLock the value
localUse only inside a function
$(command)Save output of a command

26 Oct 2025

πŸ’» Top 100+ Linux Commands for Middleware & DevOps Engineers ⚙️

πŸ’» Top 100 Linux Commands for Middleware & DevOps Engineers ⚙️ (Includes SSH, SSH-Key & Telnet) | MiddlewareBox
  • πŸ’» Linux is the backbone of every Middleware and DevOps ecosystem — running enterprise tools like WebSphere, JBoss, Jenkins, Docker, and Ansible.
  • ⚙️ This post brings together 100+ essential Linux commands — covering file management, networking, SSH, cron jobs, and systemctl operations used daily by engineers.
  • πŸ” Learn secure connectivity practices with SSH and SSH-Key management, plus essential testing using Telnet.
  • πŸš€ Ideal for Middleware Engineers, DevOps professionals, and System Administrators aiming to strengthen their Linux command-line mastery.


πŸ“ 1️⃣ File & Directory Management

🧩 Command πŸ’‘ Description
pwdShow current directory
ls -lhList files in readable format
ls -lrtSort files by modification time
cd /opt/appChange directory
mkdir -p /data/logs/archiveCreate nested directories
rm -rf /tmp/logsRemove directory recursively
cp -rp /opt/config /backup/Copy files with permissions
mv old.log new.logRename or move file
cat file.txtDisplay file content
du -sh /optShow directory size
df -hDisplay filesystem usage
touch file.txtCreate an empty file

πŸ” Command πŸ’‘ Description
grep "error" logfile.logSearch keyword in file
grep -i "critical" /var/log/syslogCase-insensitive search
grep -r "Exception" /opt/app/Recursive search
awk '{print $1,$3}' logfile.logPrint specific columns
sort -u file.txtSort and remove duplicates
uniq -c file.txtCount unique lines
wc -l file.txtCount number of lines
head -n 10 file.txtShow first 10 lines
tail -n 50 logfile.logShow last 50 lines
tail -f jenkins.logWatch logs live
sed -i 's/http:/https:/g' nginx.confReplace text in file

⚙️ 3️⃣ Process & Performance Monitoring

⚙️ Command πŸ’‘ Description
topReal-time process viewer
htopInteractive process viewer
ps -ef | grep javaShow running Java processes
kill -9 <pid>Kill process by ID
lsof -i :8080Find process using a port
vmstat 2 5Show CPU/memory stats every 2s
iostat -x 1Disk performance summary
free -mMemory usage (in MB)
uptimeSystem load average
sar -u 2 3CPU utilization snapshot
journalctl -u nginx.service -fFollow logs for systemd service
dmesg | tail -20Check kernel/system logs

🌐 4️⃣ Network & Connectivity

🌍 Command πŸ’‘ Description
ping www.google.comCheck connectivity
curl -I https://middlewarebox.comGet HTTP headers
wget https://example.com/file.zipDownload file
ip addrDisplay IP addresses
ip routeShow routing table
ss -tulwnShow listening ports
netstat -plantDisplay active connections
nc -zv 10.0.0.5 22Test port access
traceroute 8.8.8.8Trace route to host
nslookup middlewarebox.comDNS lookup
dig middlewarebox.comDetailed DNS query

πŸ”‘ 5️⃣ SSH & Secure Connectivity Commands

πŸ”‘ Command πŸ’‘ Description
ssh user@hostnameConnect to remote server
ssh -i ~/.ssh/id_rsa user@10.0.0.10Use specific private key
ssh-copy-id user@serverCopy SSH key for passwordless login
ssh -v user@serverVerbose SSH connection (debug)
scp file.txt user@remote:/tmp/Securely copy files between systems
rsync -avz /opt/app/ user@server:/backup/Sync files securely over SSH
ssh-agent bashStart SSH authentication agent
ssh-add ~/.ssh/id_rsaAdd SSH private key to agent

πŸ” 6️⃣ SSH-Key Management (Essential for DevOps)

πŸ” Command πŸ’‘ Description
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Generate a new SSH key pair
ls ~/.ssh/List existing SSH keys and configs
cat ~/.ssh/id_rsa.pubView your public key
ssh-copy-id user@serverCopy public key for passwordless login
ssh -i ~/.ssh/id_rsa user@serverConnect using a private key
chmod 700 ~/.sshSecure SSH directory
chmod 600 ~/.ssh/id_rsa & chmod 644 ~/.ssh/id_rsa.pubSet correct key permissions
ssh -T git@github.comTest SSH auth with GitHub
ssh-agent bash & ssh-add ~/.ssh/id_rsaLoad key into SSH agent

πŸ’‘ TIP: SSH keys allow secure, passwordless access between servers — commonly used in Jenkins, Ansible, and Git integrations for DevOps automation.


🌍 7️⃣ Telnet Commands (Essential)

🌍 Command πŸ’‘ Description
telnet hostname portTest basic TCP connectivity
telnet 10.0.0.10 443Check HTTPS port reachability
telnet mail.server.com 25Test SMTP mail server connection

⚙️ 8️⃣ User & Permission Management

πŸ‘€ Command πŸ’‘ Description
whoamiShow current user
idDisplay user ID and groups
adduser devopsCreate a new user
passwd devopsSet user password
usermod -aG sudo devopsAdd user to sudo group
groups devopsShow user group memberships
chmod +x deploy.shMake script executable
chown root:root /opt/appChange file ownership

πŸ“¦ 9️⃣ Compression & Archiving

πŸ“¦ Command πŸ’‘ Description
tar -cvf backup.tar /dataCreate tar archive
tar -xvf backup.tarExtract tar file
gzip file.txtCompress file
gunzip file.txt.gzDecompress file
zip -r backup.zip /opt/appCreate zip archive
unzip backup.zipExtract zip archive

πŸ› ️ 1️⃣0️⃣ System & Service Management

πŸ› ️ Command πŸ’‘ Description
systemctl status firewalldCheck firewalld service status
systemctl start firewalldStart firewalld service
systemctl stop firewalldStop firewalld service
systemctl enable firewalldEnable firewalld at boot
systemctl disable firewalldDisable firewalld from starting at boot

πŸ“¦ 1️⃣1️⃣ Package Management

πŸ“¦ Command πŸ’‘ Description
apt updateUpdate package lists (Debian/Ubuntu)
apt install <package>Install package (Debian/Ubuntu)
yum updateUpdate packages (RHEL/CentOS)
yum install telnet / apt install telnetInstall Telnet client on RHEL / Ubuntu

⏰ 1️⃣2️⃣ Cron & Scheduling (Small but essential)

⏰ Command πŸ’‘ Description
crontab -lList current user's cron jobs
crontab -eEdit current user's cron jobs using the default editor
sudo crontab -e -u usernameEdit another user's cron jobs (requires sudo)
cat /etc/crontabView system-wide cron file

🧠 πŸ”Ÿ Productivity & Shortcuts

⚡ Command πŸ’‘ Description
historyShow previous commands
!!Re-run last command
!sudoRun last command as sudo
alias ll='ls -la'Create command alias
unalias llRemove alias
ctrl + rSearch command history
clearClear terminal screen