0% found this document useful (0 votes)
16 views28 pages

Linux Book

Uploaded by

murselixhevdet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views28 pages

Linux Book

Uploaded by

murselixhevdet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

50 Linux topics ranging from basic to advanced,

along with relevant commands and practical


scenarios. Each topic includes a brief explanation
and related commands. 📚

Follow – Krishan Bhatt👨‍💻✅

Basic Topics:

1. File Management
• Commands: ls, cp, mv, rm, touch
• Scenario: List all files in a directory, copy a file, move files between directories, and
delete files.
2. Directory Management
• Commands: mkdir, rmdir, cd, pwd
• Scenario: Create and navigate through directories, and remove empty directories.
3. File Permissions
• Commands: chmod, chown, chgrp
• Scenario: Change file permissions to control user access.
4. Viewing and Editing Files
• Commands: cat, less, more, vi, nano
• Scenario: View the contents of a file and edit it using text editors.
5. Managing Links
• Commands: ln, ln -s
• Scenario: Create hard and soft links to files.
6. Process Management
• Commands: ps, top, kill, htop, bg, fg, nice
• Scenario: Monitor running processes and terminate or change their priority.
7. Managing Users and Groups
• Commands: useradd, userdel, usermod, groupadd
• Scenario: Create, modify, and delete users and groups.
8. Package Management (Debian-based)
• Commands: apt-get, dpkg
• Scenario: Install, remove, and update packages on Debian-based systems.
9. Package Management (RHEL-based)
• Commands: yum, dnf, rpm
• Scenario: Install, update, and remove packages on Red Hat-based systems.
10. Disk Management
• Commands: df, du, fdisk, mount, umount
• Scenario: Check disk usage, partition a disk, and mount/unmount file systems.
11. Service Management
• Commands: systemctl, service, chkconfig
• Scenario: Start, stop, enable, and disable services on a system.
12. Networking Basics
• Commands: ip, ifconfig, ping, netstat, traceroute
• Scenario: Check network configuration, test connectivity, and display active
connections.
13. SSH and Remote Access
• Commands: ssh, scp, rsync
• Scenario: Securely connect to remote systems and transfer files between them.
14. Cron Jobs
• Commands: crontab
• Scenario: Schedule regular tasks to automate scripts or system commands.
15. System Logs
• Commands: journalctl, dmesg, tail, /var/log
• Scenario: View system logs for troubleshooting and auditing purposes.
16. Text Processing Tools
• Commands: grep, awk, sed, cut, sort
• Scenario: Search, filter, and modify text data from files or command output.
17. Archiving and Compression
• Commands: tar, gzip, gunzip, zip, unzip
• Scenario: Compress files into archives and extract them.
18. File Search
• Commands: find, locate
• Scenario: Locate files based on name, type, or modification date.
19. Basic Shell Scripting
• Commands: bash, sh
• Scenario: Automate tasks using simple shell scripts.
20. Environment Variables
• Commands: export, env, set
• Scenario: Set and manage environment variables.

Intermediate Topics:

21. Advanced File Permissions: ACL


• Commands: getfacl, setfacl
• Scenario: Assign more granular file permissions using Access Control Lists.
22. LVM (Logical Volume Manager)
• Commands: pvcreate, vgcreate, lvcreate, lvextend
• Scenario: Create and manage logical volumes for flexible disk space allocation.
23. Kernel Management
• Commands: uname, dmesg, modprobe, lsmod
• Scenario: View kernel information and manage kernel modules.
24. Networking Configuration
• Commands: ip, nmcli, /etc/network/interfaces
• Scenario: Set static IP addresses and configure network interfaces.
25. Firewall Management
• Commands: firewalld, iptables
• Scenario: Set up rules to control inbound and outbound traffic on the system.
26. SELinux
• Commands: getenforce, setenforce, semanage
• Scenario: Enable, disable, and troubleshoot SELinux for security policies.
27. Managing RAID
• Commands: mdadm
• Scenario: Create and manage software RAID for redundancy and performance.
28. Backup and Restore
• Commands: rsync, tar, dd
• Scenario: Perform system backups and restore from a backup image.
29. Swap Management
• Commands: swapon, swapoff, mkswap
• Scenario: Configure swap space for system memory management.
30. NFS (Network File System)
• Commands: mount, nfsstat, /etc/exports
• Scenario: Share directories over the network using NFS.
31. Samba (SMB)
• Commands: smbclient, smb.conf
• Scenario: Configure Samba for file sharing between Linux and Windows systems.
32. Advanced Shell Scripting
• Commands: bash, zsh, functions, loops
• Scenario: Create complex automation scripts with loops and conditional statements.
33. Scheduling with at
• Commands: at, atq, atrm
• Scenario: Schedule one-time tasks to run at specific times.
34. Basic Performance Monitoring
• Commands: top, iotop, vmstat, sar
• Scenario: Monitor CPU, memory, and disk I/O performance on the system.
35. System Boot Process
• Commands: systemd-analyze, grub2, /boot/
• Scenario: Analyze boot performance and troubleshoot boot issues.
36. Creating and Managing Partitions
• Commands: fdisk, parted, mkfs
• Scenario: Create, delete, and format disk partitions.
37. User Authentication with PAM
• Commands: pam-auth-update, /etc/pam.d/
• Scenario: Configure Pluggable Authentication Modules for security.
38. Troubleshooting with strace and lsof
• Commands: strace, lsof
• Scenario: Debug program execution and identify open file descriptors.
39. Setting Up a Web Server (Apache/Nginx)
• Commands: apachectl, nginx, httpd
• Scenario: Set up and configure a web server for hosting websites.
40. Database Management (MySQL/PostgreSQL)
• Commands: mysql, psql
• Scenario: Install, configure, and manage a MySQL or PostgreSQL database server.

Advanced Topics:

41. Kernel Tuning with sysctl


• Commands: sysctl
• Scenario: Modify kernel parameters at runtime for performance tuning.
42. Virtualization with KVM
• Commands: virsh, virt-install
• Scenario: Create and manage virtual machines on Linux with KVM.
43. Docker and Containerization
• Commands: docker, docker-compose
• Scenario: Set up, run, and manage containers on Linux.
44. Automation with Ansible
• Commands: ansible-playbook
• Scenario: Automate infrastructure provisioning using Ansible playbooks.
45. High Availability with Pacemaker and Corosync
• Commands: pcs, crm
• Scenario: Set up a highly available cluster for critical services.
46. Advanced Networking with iptables/nftables
• Commands: iptables, nft
• Scenario: Configure complex firewall rules for secure network management.
47. Load Balancing with HAProxy
• Commands: haproxy, systemctl
• Scenario: Set up load balancing for web applications.
48. Email Server Setup (Postfix)
• Commands: postfix, mail
• Scenario: Configure a Postfix mail server for sending and receiving emails.
49. Advanced Monitoring with Nagios/Zabbix
• Commands: nagios, zabbix-server
• Scenario: Set up and configure monitoring tools to track system and service health.
50. Cloud Integration (AWS/GCP)
• Commands: aws-cli, `gcloud

Basic Topics with Examples:

1. File Management

• Commands: ls, cp, mv, rm, touch

• Example:

ls -l # List all files with details

cp file1.txt /tmp # Copy file1.txt to /tmp

mv file1.txt /tmp # Move file1.txt to /tmp

rm file1.txt # Delete file1.txt

touch file1.txt # Create an empty file named file1.txt

2. Directory Management

• Commands: mkdir, rmdir, cd, pwd

• Example:

mkdir /tmp/new_dir # Create a new directory in /tmp


cd /tmp/new_dir # Change directory to /tmp/new_dir

pwd # Print working directory

rmdir /tmp/new_dir # Remove an empty directory

3. File Permissions

• Commands: chmod, chown, chgrp

• Example:

chmod 755 file1.txt # Set file1.txt permissions to rwxr-xr-x

chown user1 file1.txt # Change ownership of file1.txt to user1

chgrp group1 file1.txt # Change the group of file1.txt to group1

4. Viewing and Editing Files

• Commands: cat, less, more, vi, nano

• Example:

cat file1.txt # Display the contents of file1.txt

less file1.txt # View large file with less command

vi file1.txt # Edit file1.txt with vi editor

nano file1.txt # Edit file1.txt with nano editor

5. Managing Links

• Commands: ln, ln -s

• Example:
ln file1.txt file1_link # Create a hard link to file1.txt

ln -s file1.txt file1_slink # Create a symbolic link to file1.txt

6. Process Management

• Commands: ps, top, kill, htop, bg, fg, nice

• Example:

ps aux # Show all running processes

top # Display real-time process info

kill -9 1234 # Forcefully terminate process with PID 1234

nice -n 10 myscript # Run myscript with lower priority

7. Managing Users and Groups

• Commands: useradd, userdel, usermod, groupadd

• Example:

useradd user1 # Add a new user

userdel user1 # Delete a user

usermod -aG sudo user1 # Add user1 to the sudo group

groupadd group1 # Create a new group

8. Package Management (Debian-based)

• Commands: apt-get, dpkg

• Example:
apt-get update # Update package repository

apt-get install apache2 # Install Apache web server

dpkg -i package.deb # Install package using dpkg

9. Package Management (RHEL-based)

• Commands: yum, dnf, rpm

• Example:

yum install httpd # Install Apache on RHEL-based systems

dnf update # Update packages on RHEL-based systems

rpm -ivh package.rpm # Install package using rpm

10. Disk Management

• Commands: df, du, fdisk, mount, umount

• Example:

df -h # Show disk usage in human-readable format

du -sh /home/user1 # Show disk usage for a specific directory

fdisk /dev/sdb # Manage partitions on a disk

mount /dev/sdb1 /mnt # Mount the disk /dev/sdb1 to /mnt

umount /mnt # Unmount the disk from /mnt

11. Service Management

• Commands: systemctl, service, chkconfig

• Example:
systemctl start httpd # Start Apache service

systemctl enable httpd # Enable Apache to start on boot

service apache2 restart # Restart Apache on Debian-based systems

chkconfig httpd on # Enable Apache on RHEL-based systems

12. Networking Basics

• Commands: ip, ifconfig, ping, netstat, traceroute

• Example:

ip addr show # Show IP address information

ifconfig eth0 # Show details of network interface eth0

ping google.com # Ping a remote host

netstat -tuln # Show open ports

traceroute google.com # Trace the network route to a remote host

13. SSH and Remote Access

• Commands: ssh, scp, rsync

• Example:

ssh user@remote_host # SSH into a remote system

scp file1.txt user@remote:/tmp # Copy file to a remote system

rsync -av /src/ /dest/ # Sync files between local and remote systems

14. Cron Jobs


• Commands: crontab

• Example:

crontab -e # Edit cron jobs

# Example cron job: Run script every day at 5 AM

0 5 * * * /home/user/myscript.sh

15. System Logs

• Commands: journalctl, dmesg, tail, /var/log

• Example:

journalctl -xe # View detailed system logs

dmesg # View kernel log messages

tail -f /var/log/syslog # Follow system log in real-time

16. Text Processing Tools

• Commands: grep, awk, sed, cut, sort

• Example:

grep 'error' /var/log/syslog # Search for 'error' in syslog

awk '{print $1, $2}' file1.txt # Extract and print the first two columns

sed 's/foo/bar/g' file1.txt # Replace 'foo' with 'bar' in file1.txt

cut -d: -f1 /etc/passwd # Extract the first field from /etc/passwd

sort file1.txt # Sort the contents of a file


17. Archiving and Compression

• Commands: tar, gzip, gunzip, zip, unzip

• Example:

tar -czvf archive.tar.gz /dir # Create a compressed archive of /dir

gzip file1.txt # Compress file1.txt

gunzip file1.txt.gz # Decompress file1.txt.gz

zip archive.zip file1.txt # Create a ZIP archive

unzip archive.zip # Unzip the archive

18. File Search

• Commands: find, locate

• Example:

find / -name file1.txt # Search for file1.txt

locate file1.txt # Locate the file using the updatedb cache

19. Basic Shell Scripting

• Commands: bash, sh

• Example:

#!/bin/bash

echo "Hello, World!" # A basic shell script that prints a message

20. Environment Variables


• Commands: export, env, set

• Example:

export VAR_NAME="value" # Set an environment variable

env # Display all environment variables

Intermediate Topics with Examples:

21. Advanced File Permissions: ACL

• Commands: getfacl, setfacl

• Example:

setfacl -m u:user1:rwx file1.txt # Add ACL for user1 to file1.txt

getfacl file1.txt # Display ACL of file1.txt

22. LVM (Logical Volume Manager)

• Commands: pvcreate, vgcreate, lvcreate, lvextend

• Example:

pvcreate /dev/sdb # Create a physical volume on /dev/sdb

vgcreate vg_data /dev/sdb # Create a volume group

lvcreate -L 10G -n lv_data vg_data # Create Lvm

Intermediate Topics with Examples (continued):


23. Kernel Management

• Commands: uname, dmesg, modprobe, lsmod

• Example:

uname -r # Display the running kernel version

dmesg | grep -i error # View kernel log messages for errors

modprobe -r module_name # Remove a kernel module

lsmod # List all loaded kernel modules

24. Networking Configuration

• Commands: ip, nmcli, /etc/network/interfaces

• Example:

ip addr add 192.168.1.100/24 dev eth0 # Assign IP address to eth0

nmcli device show # Show network device details

nmcli con up "Wired connection 1" # Bring up a specific network connection

25. Firewall Management

• Commands: firewalld, iptables

• Example:
firewall-cmd --zone=public --add-port=80/tcp --permanent # Open HTTP port 80

firewall-cmd --reload # Reload firewalld rules

iptables -L # List all iptables rules

iptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSH access

26. SELinux

• Commands: getenforce, setenforce, semanage

• Example:

getenforce # Check if SELinux is enforcing or permissive

setenforce 0 # Temporarily set SELinux to permissive mode

semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?" # Allow HTTP access to


custom web directory

27. Managing RAID

• Commands: mdadm

• Example:

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb # Create RAID1


with 2 devices

mdadm --detail /dev/md0 # Show RAID array details


28. Backup and Restore

• Commands: rsync, tar, dd

• Example:

rsync -av /source/ /destination/ # Sync files between directories

tar -czf backup.tar.gz /mydata # Create a compressed backup

dd if=/dev/sda of=/backup.img bs=4M # Create a raw disk backup

29. Swap Management

• Commands: swapon, swapoff, mkswap

• Example:

mkswap /dev/sdb1 # Create a swap space on /dev/sdb1

swapon /dev/sdb1 # Enable swap space

swapoff /dev/sdb1 # Disable swap space

30. NFS (Network File System)

• Commands: mount, nfsstat, /etc/exports

• Example:
echo "/shared_dir 192.168.1.0/24(rw,sync,no_root_squash)" >> /etc/exports # Export a
directory over NFS

exportfs -r # Apply NFS export changes

mount -t nfs 192.168.1.100:/shared_dir /mnt/nfs_mount # Mount the NFS


share

nfsstat # Show NFS statistics

31. Samba (SMB)

• Commands: smbclient, smb.conf

• Example:

smbclient -L //localhost # List shared directories on a local Samba server

smb.conf: [shared] # Example Samba configuration

path = /srv/samba/shared

read only = no

browsable = yes

systemctl restart smb # Restart the Samba service to apply changes

32. Advanced Shell Scripting

• Commands: bash, zsh, functions, loops

• Example:

#!/bin/bash
function greet {

echo "Hello, $1"

for user in Alice Bob; do

greet $user

done

33. Scheduling with at

• Commands: at, atq, atrm

• Example:

at 02:00 # Schedule a task at 2 AM

at> echo "Backup completed" >> /var/log/backup.log

atq # View the queue of scheduled jobs

atrm 1 # Remove job number 1 from the queue

34. Basic Performance Monitoring

• Commands: top, iotop, vmstat, sar

• Example:

top # Monitor system processes in real-time

iotop # Monitor disk I/O usage


vmstat 5 # Display system memory and CPU usage every 5 seconds

sar -u 1 3 # Show CPU usage every 1 second for 3 intervals

35. System Boot Process

• Commands: systemd-analyze, grub2, /boot/

• Example:

systemd-analyze blame # Show time taken for each service during boot

grub2-mkconfig -o /boot/grub2/grub.cfg # Regenerate GRUB configuration

ls /boot # View contents of the /boot directory

36. Creating and Managing Partitions

• Commands: fdisk, parted, mkfs

• Example:

fdisk /dev/sdb # Create partitions on /dev/sdb

parted /dev/sdb mklabel gpt # Create a GPT partition table

mkfs.ext4 /dev/sdb1 # Format the partition with ext4 filesystem

37. User Authentication with PAM


• Commands: pam-auth-update, /etc/pam.d/

• Example:

pam-auth-update # Update PAM authentication modules

vi /etc/pam.d/sshd # Edit SSH PAM configuration to restrict root access

38. Troubleshooting with strace and lsof

• Commands: strace, lsof

• Example:

strace -p 1234 # Trace system calls made by process 1234

lsof -i :80 # List all processes using port 80

39. Setting Up a Web Server (Apache/Nginx)

• Commands: apachectl, nginx, httpd

• Example:

apachectl start # Start Apache web server

vi /etc/httpd/conf/httpd.conf # Edit Apache configuration file

systemctl restart nginx # Restart Nginx service after making changes


40. Database Management (MySQL/PostgreSQL)

• Commands: mysql, psql

• Example:

mysql -u root -p # Log in to MySQL

CREATE DATABASE mydb; # Create a new MySQL database

psql -U postgres # Log in to PostgreSQL

CREATE DATABASE mydb; # Create a new PostgreSQL database

Advanced Topics with Examples:

41. Kernel Tuning with sysctl

• Commands: sysctl

• Example:

sysctl -a # List all kernel parameters

sysctl net.ipv4.ip_forward=1 # Enable IP forwarding

sysctl -p # Apply changes from sysctl.conf

42. Virtualization with KVM


• Commands: virsh, virt-install

• Example:

virt-install --name myvm --ram 2048 --disk


path=/var/lib/libvirt/images/myvm.img,size=10 --vcpus 2 --os-type linux --os-variant
ubuntu20.04 --network bridge=virbr0 --graphics none --console pty,target_type=serial --
cdrom /var/lib/libvirt/boot/ubuntu.iso

virsh start myvm # Start the virtual machine

virsh list # List running virtual machines

43. Docker and Containerization

• Commands: docker, docker-compose

• Example:

docker run -d -p 80:80 nginx # Run an Nginx container in detached mode

docker ps # List running containers

docker-compose up -d # Start containers defined in a docker-compose.yml

44. Automation with Ansible

• Commands: ansible, ansible-playbook, ansible-inventory

• Example:

# Check the connectivity of the hosts using Ansible ping module

ansible all -m ping -i inventory


# Example of running a playbook

ansible-playbook -i inventory deploy_web.yml

# deploy_web.yml (sample playbook)

---

- hosts: webservers

become: yes

tasks:

- name: Install Nginx

yum:

name: nginx

state: present

- name: Start Nginx service

service:

name: nginx

state: started

Scenario: Automate the deployment of Nginx on multiple servers using an Ansible


playbook, ensuring installation and service startup.

45. Container Orchestration with Kubernetes

• Commands: kubectl, minikube, kubeadm

• Example:

kubectl get pods # List all running pods


kubectl apply -f deployment.yml # Apply a Kubernetes configuration (Deployment)

minikube start # Start a local Kubernetes cluster

# Example of a basic deployment configuration (deployment.yml)

---

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

spec:

replicas: 3

selector:

matchLabels:

app: nginx

template:

metadata:

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1.14.2

ports:

- containerPort: 80

Scenario: Deploy a containerized Nginx application with 3 replicas using Kubernetes.

46. Configuring Load Balancing


• Commands: haproxy, nginx, keepalived

• Example:

# Nginx as a load balancer example

vi /etc/nginx/nginx.conf

# Add the following in the config file

http {

upstream backend {

server backend1.example.com;

server backend2.example.com;

server {

listen 80;

location / {

proxy_pass http://backend;

systemctl restart nginx # Restart Nginx to apply changes

Scenario: Set up load balancing with Nginx to distribute traffic across multiple backend
servers.

47. CI/CD Pipelines (Jenkins/GitLab CI)


• Commands: jenkins-cli, gitlab-runner

• Example:

# Running Jenkins jobs from the command line

java -jar jenkins-cli.jar -s http://localhost:8080/ build my_job

# GitLab CI pipeline example (.gitlab-ci.yml)

stages:

- build

- deploy

build_job:

stage: build

script:

- echo "Building the project"

- make build

deploy_job:

stage: deploy

script:

- echo "Deploying the project"

- scp build artifact user@server:/path/to/deploy

Scenario: Automate project build and deployment using Jenkins or GitLab CI pipelines.

48. Log Management and Centralization (ELK Stack)

• Commands: logstash, elasticsearch, kibana, filebeat


• Example:

# Filebeat configuration example (/etc/filebeat/filebeat.yml)

filebeat.inputs:

- type: log

paths:

- /var/log/syslog

output.logstash:

hosts: ["localhost:5044"]

# Starting Filebeat to ship logs

systemctl start filebeat

Scenario: Centralize and analyze logs using the ELK stack (Elasticsearch, Logstash, and
Kibana) with Filebeat for log collection.

49. High Availability with Pacemaker/Corosync

• Commands: pcs, crm, corosync

• Example:

# Authenticate cluster nodes

pcs cluster auth node1.example.com node2.example.com

# Create and start the cluster

pcs cluster setup --name mycluster node1.example.com node2.example.com


pcs cluster start --all

# View cluster status

pcs status

# Add a resource to the cluster (e.g., an IP address resource)

pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.1.100 cidr_netmask=24


op monitor interval=30s

Scenario: Set up a highly available cluster with Pacemaker and Corosync for failover of
critical resources like IP addresses or services.

50. Linux Security Auditing (Lynis/AIDE)

• Commands: lynis, aide, /etc/aide.conf

• Example:

# Run a Lynis security audit

lynis audit system

You might also like