Master Linux Command Line: Essential Commands and Tips for System Administration
This comprehensive guide walks you through Linux fundamentals, covering everything from system overview, disk and file management, security practices, shell scripting basics, networking tools, system monitoring, package management, backup utilities, and practical command examples to help you become proficient in Linux administration.
1. Linux Overview
Linux is a free, open‑source Unix‑like operating system that supports POSIX and runs on multiple hardware platforms. It provides a multi‑user, multitasking environment with a rich set of command‑line tools.
1.1 What is Linux?
Linux is a free operating system based on Unix, supporting 32‑bit and 64‑bit hardware. It runs most Unix tools, applications, and network protocols.
1.2 Differences between Unix and Linux
Open source : Linux is free and its source code can be modified and redistributed.
Cross‑platform : Linux runs on many hardware platforms, while Unix is more limited.
GUI : Linux provides both command‑line and graphical interfaces; Unix traditionally offers only a command line.
Hardware requirements : Linux works on lower‑end hardware; Unix often requires more powerful machines.
User base : Linux is used by a wide range of users, from individuals to enterprises.
1.3 Linux Kernel
The kernel manages hardware and software resources, handling memory, process, and device management.
1.4 Linux Architecture
Linux consists of two main spaces:
User space : Contains user applications, libraries, and utilities.
Kernel space : Includes system call interface, the kernel itself, and architecture‑dependent code.
2. Disk, Directory, File
In Linux, everything is treated as a file, including devices. Key directories include /bin, /etc, /home, /usr, /proc, /root, /sbin, /dev, /mnt, /boot, /lib, /tmp, /var, and /lost+found.
2.1 Inode
An inode stores metadata about a file (owner, size, timestamps, block pointers). It enables the mapping between logical file structure and physical storage.
2.2 Hard and Soft Links
Hard link : Direct reference to an inode; cannot span filesystems and cannot link directories.
Soft (symbolic) link : Path‑based reference; can cross filesystems and point to directories.
3. Security
Typical hardening steps after a fresh Linux installation include:
Add non‑root users and disable root SSH login.
Use SSH key authentication and disable password login.
Enable a firewall (iptables) and disable SELinux if not needed.
Install fail2ban to block brute‑force attacks.
Restrict SSH access to specific IP ranges or VPN.
Limit command history length.
Restrict outbound traffic to necessary services.
Apply application‑level security measures.
3.1 Common Attacks
CC (Challenge‑Response) attack : Simulates many legitimate requests to exhaust resources.
DDOS attack : Distributed denial‑of‑service using multiple compromised hosts.
SQL injection : Unsanitized input allows attackers to execute arbitrary queries.
4. Shell
A shell script is a text file containing a sequence of commands. The default login shell is /bin/bash.
4.1 Basic Syntax
Comments start with #.
Variables: system‑defined (uppercase) and user‑defined.
Exit status: $? equals 0 on success.
Special variables: $0, $1 … $9, $@, $#.
4.2 Control Structures
# if…then…else…fi
if [ condition ]; then
# commands
else
# commands
fi
# case statement
case $var in
pattern1) commands ;;&
pattern2) commands ;;
esac
# for loop
for i in list; do
# commands
done
# while loop
while [ condition ]; do
# commands
done4.3 Common Commands
chmod, chown, cp, mv, rm, ln, find, grep, sed, awk.
Redirection: >, >>, 2>&1, &>.
5. Programming Exercises
Examples include checking if a file is a character device and copying it, creating a group and adding users, deleting a range of user accounts, and writing sed scripts to modify files.
6. Practical Tasks
Choosing a Linux distribution (e.g., Ubuntu for desktop, CentOS/RHEL for servers), planning system installation, partitioning, creating users, and configuring services.
6.1 Performance Tuning
Disable unnecessary daemons.
Turn off the GUI.
Adjust kernel parameters.
Tune CPU, memory, filesystem, and network subsystems.
7. File Management Commands
cat: Concatenate and display files. chmod: Change file permissions. chown: Change file owner/group. cp: Copy files/directories. ln: Create hard or symbolic links. locate, whereis, which: Find files or commands. more, less, head, tail, sed, awk, grep, wc.
8. Disk Management Commands
cd: Change directory. df: Report filesystem disk space usage. du: Estimate file and directory space usage. ls: List directory contents with options for sorting, showing hidden files, and detailed listings. mkdir, pwd, rmdir.
9. Network Communication Commands
ifconfig: Show or configure network interfaces. iptables: Manage firewall rules (e.g., block IP, open port 80). netstat: Display network connections, routing tables, and interface statistics. ping: Test reachability of a host. telnet: Remote login (useful for testing services).
10. System Management Commands
date: Display or set system date and time. free: Show memory usage. kill, ps: Process management. rpm, yum: Package management for Red Hat based systems. top: Real‑time process monitoring.
11. Backup and Compression Commands
bzip2, gzip: Compress and decompress files. tar: Archive files; combine with -z (gzip) or -j (bzip2) for compression. unzip: Extract ZIP archives.
Follow "Open Source Linux" and star the account to boost your IT skills!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
