Linux命令速查
来源
原始文档: linux_cmd.md
核心内容
Linux 系统管理常用命令和操作速查手册。
历史记录控制
unset HISTFILE # 临时不记录命令历史
文件系统操作
# 使用 debootstrap 创建文件系统
sudo debootstrap --arch=arm64 focal ./ubuntu-20.04-arm64 https://ports.ubuntu.com/
# 远程同步文件系统
rsync -avz --numeric-ids --exclude=/proc --exclude=/sys --exclude=/dev root@device:/ ./sysroot
# 清理缓存
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
chroot 操作
# 挂载必要的文件系统
sudo mount --bind /dev /mnt/sysroot/dev
sudo mount --bind /proc /mnt/sysroot/proc
sudo mount --bind /sys /mnt/sysroot/sys
# 进入 chroot
sudo chroot /mnt/sysroot
# 退出并卸载
exit
sudo umount /mnt/sysroot/dev
sudo umount /mnt/sysroot/proc
sudo umount /mnt/sysroot/sys
编辑器配置
# 设置默认编辑器 (系统级)
sudo vim /etc/environment
# 添加: EDITOR=vim, VISUAL=vim
# 设置默认编辑器 (用户级)
echo 'export EDITOR=vim' >> ~/.bashrc
source ~/.bashrc
别名设置
# 修改 ls 时间格式 (bash)
echo 'alias ls="ls --time-style=\"+%Y-%m-%d %H:%M:%S\""' >> ~/.bashrc
source ~/.bashrc
# 修改 ls 时间格式 (zsh)
echo 'alias ls="ls --time-style=\"+%Y-%m-%d %H:%M:%S\""' >> ~/.zshrc
source ~/.zshrc
htop 使用
| 快捷键 | 功能 |
|---|---|
| F6 | 选择排序方式 |
| F5 | 树状模式 |
| F2 | 设置 |
| t | 切换 CPU 柱状图 |
| k | kill 进程 |
| u | 按用户过滤 |
CPU排序: CPU%, TIME+, STATE
内存排序: MEM%, RES, VIRT, SHR, SWAP
代理设置
# 临时代理 (git)
git -c http.proxy=http://127.0.0.1:8118 clone <url>
# SOCKS5 代理
export ALL_PROXY="socks5h://127.0.0.1:6666"
export http_proxy="$ALL_PROXY"
export https_proxy="$ALL_PROXY"
# 取消代理
unset ALL_PROXY all_proxy http_proxy https_proxy
磁盘使用
du -sh # 当前目录总大小
du -h --max-depth=1 # 子目录明细
du -sh ./dir # 指定目录大小
公网 IP
curl -s https://ifconfig.me # IPv6
curl -4 -s https://ifconfig.me # IPv4
压缩归档
tar -czvf archive.tar.gz folder/ # 压缩
tar -xzvf archive.tar.gz # 解压
Logrotate 配置
sudo vim /etc/logrotate.d/frps
配置内容:
/var/log/frps.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 640 user group
postrotate
systemctl kill -s HUP frps 2>/dev/null || true
endscript
}
测试配置:
sudo logrotate -d /etc/logrotate.d/frps # 调试
sudo logrotate -f /etc/logrotate.d/frps # 强制轮转
关键要点
- 使用
chroot需要在退出后正确卸载挂载点 htop提供交互式进程管理,支持多种排序方式logrotate是日志管理的核心工具,需定期测试配置- 代理环境变量区分大小写,注意
ALL_PROXY和all_proxy
相关实体
- Linux - Linux 操作系统
- Shell - Shell 脚本
- htop - 交互式进程查看器
- logrotate - 日志轮转工具