Linux 服务器管理 – 完整笔记 (CIITM Dhanbad)
发布: (2025年12月3日 GMT+8 12:45)
5 min read
原文: Dev.to
Source: Dev.to
UNIT – I : Linux Introduction, File System & Basic Commands
1. Introduction to Linux
- Linux 是一个 免费、开源、安全且稳定 的操作系统。
- 基于 UNIX,广泛用于:
- 服务器
- 云系统
- 网络
- 网络安全
- 开发
- 其特点:
- 高安全性
- 性能快速
- 抗病毒
- 多用户环境
2. Basic Features of Linux
- 多用户 & 多任务
- 可移植 & 开源
- 强大的网络支持
- 高度可定制
- 强大的 Shell 与脚本
3. Flavors (Distributions) of Linux
常见的 Linux 发行版:
- Ubuntu
- Debian
- RedHat (RHEL)
- Fedora
- CentOS
- Kali Linux
- Linux Mint
4. Advantages of Linux
- 免费且开源
- 极其稳定
- 无病毒
- 强大的命令行
- 支持编程与服务器
- 社区支持
5. How Linux Accesses Files
Linux 使用 inode‑based 文件系统,每个文件都有:
- inode 编号
- 文件类型
- 文件权限
- 所有者 & 组
- 大小
- 存储位置
Linux 将 一切视为文件,包括:
- 设备
- 目录
- 进程
- 套接字
6. Linux Standard Directories
| 目录 | 用途 |
|---|---|
/ | 根目录 |
/home | 用户主目录 |
/root | 超级用户主目录 |
/bin | 基本用户命令 |
/sbin | 系统管理员命令 |
/etc | 配置文件 |
/dev | 设备文件 |
/var | 日志与可变数据 |
/usr | 已安装软件 |
/tmp | 临时文件 |
7. Basic File & Directory Commands
| 命令 | 描述 |
|---|---|
pwd | 显示当前目录 |
cd | 更改目录 |
ls | 列出文件 |
cp | 复制文件 |
mv | 移动 / 重命名 |
rm | 删除文件 |
mkdir | 创建目录 |
rmdir | 删除目录 |
file | 显示文件类型 |
more, less | 查看长文件 |
8. Creating & Viewing Files using cat
cat > file.txt # create
cat file.txt # view
9. File Comparison Commands
cmp file1 file2– 逐字节比较comm file1 file2– 按行比较
10. Disk Related Commands
df -h– 显示磁盘可用空间du -sh folder– 文件夹大小mount– 挂载磁盘umount– 卸载磁盘
UNIT – II : Shells, Processes, Pipes, Filters, Scheduling & VI Editor
1. Understanding Shells
Shell 是命令解释器。常见的 Shell:
- Bash(默认)
- Zsh
- Ksh
- Tcsh
2. Processes in Linux
进程 = 正在执行的程序。常用命令:
ps # 显示进程
top # 实时监控
kill PID # 终止进程
jobs # 显示后台作业
3. Connecting Processes with Pipes
ls | wc -l
管道将 一个命令的输出 传递给 另一个命令的输入。
4. Input / Output Redirection
| 操作符 | 含义 |
|---|---|
> | 输出到文件 |
>> | 追加输出 |
2> | 重定向错误 |
&> | 输出 + 错误 |
5. Help Commands
man commandhelp commandinfo command
6. Background Processing
command &
jobs
bg %1
fg %1
7. Managing Multiple Processes
pspgrephtopkill
8. Changing Process Priority
nice -n 10 program
renice 5 PID
9. Scheduling Commands
使用 cron
crontab -e
使用 at
at 5pm
10. File & Utility Commands
| 命令 | 描述 |
|---|---|
touch | 创建空文件 |
wc | 统计行/词/字符 |
cut | 提取列 |
dd | 复制/转换数据 |
expr | 数学运算 |
bc | 计算器工具 |
11. VI / VIM Editor
模式
- 命令模式
- 插入模式
- 最后一行模式
常用命令
i " 插入
x " 删除字符
:w " 保存
:q " 退出
:wq " 保存并退出
/text " 搜索文本
12. Simple Filter Commands
prheadtailcutpastesortuniqtr
13. Regular Expression Filters
grep– 搜索模式egrep– 扩展 grepsed– 搜索并替换
示例:
sed 's/old/new/g' file.txt
UNIT – III : Shell Programming & System Administration Basics
1. Introduction to Shell Programming
Shell 脚本 是包含 Linux 命令的文本文件。
示例:
#!/bin/bash
echo "Hello Linux"
运行:
chmod +x script.sh
./script.sh
2. Shell Programming Concepts
变量
name="Abhishek"
echo $name
条件
if [ $a -gt 10 ]; then
echo "OK"
fi
循环
for i in 1 2 3; do echo $i; done
函数
hello(){ echo "Hello"; }
3. System Administration Tasks
- 用户管理
- 磁盘管理
- 网络设置
- 软件包安装
- 备份与恢复
- 系统监控
4. Configuration & Log Files
日志存放在:
/var/log/
重要文件:
/etc/passwd/etc/shadow/etc/fstab/etc/hosts
5. Linux Installation Process
- 从 USB/DVD 启动
- 创建分区
- 安装基础系统
- 安装引导加载程序
- 重启
6. System Startup / Shutdown
shutdown -h now
reboot
systemctl reboot
UNIT – IV : User Management, File System, Permissions & Networking
1. Managing User Accounts
添加用户
useradd username
passwd username
删除用户
userdel username
2. Permissions & Ownership
权限类型
- 读取 (r)
- 写入 (w)
- 执行 (x)
修改权限
chmod 755 file
更改所有者 / 组
chown user file
chgrp group file
3. Managing Groups
groupadd group
groupdel group
4. Disable User Account
usermod -L user
5. Creating & Mounting File System
mkfs.ext4 /dev/sdb1
mount /dev/sdb1 /mnt
6. Super User (su / sudo)
su
sudo command
7. Backup & Restore
cprsynctarscp
8. Installing & Removing Packages
Ubuntu/Debian
apt install package
apt remove package
RHEL/CentOS
yum install package
yum remove package