Essential Linux System Administration Techniques

Regular Expressions

Regular expressions enable pattern matching across data streams using wildcards, metacharacters, and keywords to identify and extract specific information.

Two primary syntax standards exist: Basic Regular Expressions (BRE) and Extended Regular Expressions (ERE). The key difference lies in metacharacter handling—ERE requires no escaping for symbols like +, ?, |, (), and {}.

Character Matching


.      Match any single character
[]     Match any character within brackets (e.g., [abc], [0-9])
[^]    Match any character outside brackets (e.g., [^abc])
|      Match either left or right pattern

Anchor Characters


^      Start of line
$      End of line
^PATTERN$  Match entire line
^[[:space:]]*$  Match empty lines
\<     Word start anchor
\>     Word end anchor
\<pattern>  Match whole word
</pattern>

Grouping and Quantifiers


()     Create capture groups (referenced as \1, \2, etc.)
*      Match preceding character 0+ times (greedy)
+      Match preceding character 1+ times
{m}    Match preceding character exactly m times
{m,n}  Match between m and n times

# Email validation example
egrep '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$' email_list.txt

# Mobile number validation
egrep '\<9[0-9]{9}\>' phone_numbers.txt

File Search and Management

locate Command

Quickly searches pre-built file databases (not real-time). Database updates via updatedb. Uses /var/lib/mlocate/mlocate.db.


# Install on Ubuntu
apt install -y mlocate

# Install on Rocky Linux
yum install -y plocate

# Search for files
locate *.log

find Command

Real-time, precise file searches with extensive filtering options.


# Find files by name (case-sensitive)
find /etc -name "*.conf"

# Find files by size (e.g., 10MB)
find /var -size +10M

# Find files modified within last 7 days
find /home -mtime -7

# Combine with xargs for batch operations
find /tmp -name "*.tmp" | xargs -I {} mv {} /backup/

File Compression

tar Archives


# Create archive
tar -zcf backup.tar.gz /data

# Extract archive
tar -zxf backup.tar.gz

# List contents
tar -tvf backup.tar.gz

gzip Compression


# Compress file
gzip data.csv

# Decompress file
gunzip data.csv.gz

Software Management

Core Concepts

  • ABI: Application Binary Interface (e.g., ELF for Linux, PE for Windows)
  • API: Application Programming Interface (platform-specific)
  • POSIX: Standardized interface for cross-platform development

Package Types

  • Source Packages: Require manual compilation (e.g., nginx-1.25.4.tar.gz)
  • Binary Packages: Pre-compiled (e.g., RPM, DEB)

# RPM package naming
httpd-2.4.57-15.el9.x86_64.rpm
# Breakdown: httpd (name), 2.4.57 (version), 15 (release), el9 (distribution), x86_64 (architecture)

Package Managers

rpm


# Install package
rpm -ivh vsftpd-3.0.3-49.el9.x86_64.rpm

# Query installed packages
rpm -qi tree
rpm -ql tree

dnf (RHEL/CentOS)


# Install package
dnf install httpd

# Update system
dnf update

apt (Debian/Ubuntu)


# Add repository
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

# Install package
apt install nginx

File Systems and Storage

File System Types


ext4   # Modern Linux file system
xfs    # High-performance file system
swap   # Swap space
vfat   # Windows-compatible file system

Storage Management


# Check file system usage
df -Th

# Check directory size
du -sh /var/log

# Format disk as ext4
mkfs.ext4 /dev/sdb

Partitioning with fdisk


# Create new partition (non-interactive)
echo -e 'n\np\n\n\n+5G\nw' | fdisk /dev/sdb

# Mount partition
mount /dev/sdb1 /mnt/data

RAID Cofniguration

Common RAID Levels

  • RAID 0: Stirping (speed boost, no redundancy)
  • RAID 1: Mirroring (full redundancy, 50% capacity loss)
  • RAID 5: Striping with parity (3+ disks, 1 disk fault tolerance)
  • RAID 10: Combination of RAID 1+0 (high speed + redundancy)

LVM Implementation

Logical Volume Managemant Workflow


# Create physical volumes
pvcreate /dev/sdb1 /dev/sdc1

# Create volume group
vgcreate vg0 /dev/sdb1 /dev/sdc1

# Create logical volume
lvcreate -L 5G -n lv0 vg0

# Format and mount
mkfs.xfs /dev/vg0/lv0
mount /dev/vg0/lv0 /mnt/data

Volume Expansion


# Expand logical volume
lvextend -L +2G /dev/vg0/lv0

# Resize filesystem
xfs_growfs /mnt/data

Tags: regular-expressions file-search package-management LVM RAID

Posted on Sat, 16 May 2026 06:18:24 +0000 by angershallreign