Operations 71 min read

Master Linux Command Line: From Basics to Advanced System Operations

This comprehensive guide walks you through Linux command line fundamentals, directory and file manipulation, text processing, compression, system installation, permission management, regular expressions, and disk operations, providing practical examples and code snippets for each topic.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Command Line: From Basics to Advanced System Operations

1. Linux Command Overview

The article begins with an overview of essential Linux commands for directory handling, file manipulation, and system navigation, emphasizing the importance of mastering these basics for efficient workflow.

1.1 Directory Operations

Common commands such as mkdir, cp, mv, and rm are demonstrated with examples:

# 创建目录及父目录 a/b/c/d
mkdir -p a/b/c/d
# 拷贝目录 a 到 /tmp
cp -rvf a/ /tmp/
# 移动并重命名文件
mv -vf a /tmp/b
# 删除所有文件(请谨慎使用)
rm -rvf /

1.2 File Inspection

Tools like ls, cat, less, head, and tail are used to view directory contents and file data, with options for pagination and real‑time log monitoring ( tail -f).

2. Text Processing

Commands for searching and filtering text include grep with color highlighting and context options ( -A, -B, -C), as well as awk and sed for column‑wise operations and pattern substitution.

# 查找包含 POST 的 nginx 日志
grep -rn --color POST access.log
# 显示异常前后 10 行
grep -rn --color Exception -A10 -B2 error.log

3. Compression and Archiving

The guide explains how to create and extract archives using tar with compression options ( -z for gzip, -j for bzip2) and how to handle zip / rar files after installing the necessary utilities.

# 打包并 gzip 压缩
tar cvfz files.tar.gz files
# 查看压缩包内容
tar tvf files.tar.gz
# 解压到指定目录
tar xvfz files.tar.gz -C /opt/

4. Installing Linux (CentOS 7) in a Virtual Machine

Step‑by‑step instructions cover downloading a minimal ISO, creating a VM in VirtualBox/VMware, configuring storage, network, and performing the installation, including post‑install tasks such as setting the root password.

# 下载 CentOS 7 Minimal ISO
wget -c http://ftp.sjtu.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1908.iso
# 启动虚拟机并进行安装(图示步骤省略)

5. Permissions and Ownership

Detailed explanation of Linux permission bits, the numeric (e.g., 755) and symbolic (e.g., u+x) notations, and commands chmod, chown, chgrp. Examples show how to grant execution rights to a script for its owner or group, and the effect of the sticky bit on directories like /tmp.

# 为所有者添加执行权限
chmod u+x confirm777.sh
# 将文件所有者改为 zhang3
chown zhang3:zhang3 confirm777.sh
# 为 /tmp 目录设置粘贴位
chmod +t /tmp

6. Disk Management

Procedures for adding a new disk, partitioning with fdisk, formatting (e.g., mkfs.xfs), mounting, and persisting mounts via /etc/fstab. Also covers creating swap space and using dd for disk cloning or image creation.

# 查看磁盘列表
fdisk -l
# 创建分区并写入分区表
fdisk /dev/sdb
# 格式化为 XFS
mkfs.xfs /dev/sdb1
# 挂载到 /data
mkdir /data
mount /dev/sdb1 /data
# 添加到 fstab 以实现开机自动挂载
echo "/dev/sdb1  xfs  defaults 0 0" >> /etc/fstab
# 创建 swap 分区并启用
mkswap /dev/sdb2
swapon /dev/sdb2

7. Advanced Shell Features

Explanation of pipelines ( |), redirection ( >, >>, 2>&1), conditional execution operators ( &&, ||, ;), and useful shortcuts like Ctrl+C to abort commands. Regular expressions are introduced with common metacharacters and examples using grep -E.

# 使用管道组合命令
seq 20 100 | head -n 50 | tail -n 1
# 将错误输出重定向到标准输出
cat nonexistent 2>&1
# 正则匹配示例
cat 996 | grep -E '^996'   # 行首匹配
cat 996 | grep -E 'icu+'   # 匹配 icu、icuu 等

8. Useful Tips

Use man, info, or --help for command documentation.

Enable colored man pages by adding a function to ~/.bashrc.

Leverage TAB completion to discover commands and file names quickly.

Overall, the guide equips readers with a solid foundation to navigate, manipulate, and manage Linux systems effectively.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxTutorialSystem Administration
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.