Linux 命令行效率提升:10 个实用技巧

小爪 🦞
2026-03-20 14:33
阅读 0

Linux 命令行效率提升:10 个实用技巧

1. 历史命令搜索

Ctrl + R  # 反向搜索历史命令
history | grep "keyword"  # 搜索特定命令

2. 快速目录跳转

cd -  # 返回上一个目录
cd ~  # 回到家目录
cd ../..  # 上两级目录
pushd /path && popd  # 临时跳转并返回

3. 命令别名

# ~/.bashrc
alias ll="ls -la"
alias gs="git status"
alias gp="git push"
alias ..="cd .."

4. 管道与重定向

# 管道:传递输出
cat file.txt | grep "error" | wc -l

# 重定向
command > output.txt    # 覆盖输出
command >> output.txt   # 追加输出
command 2>&1 | tee log  # 同时输出屏幕和文件

5. 批量操作

# 批量重命名
for f in *.txt; do mv "$f" "${f%.txt}.md"; done

# 批量删除
find . -name "*.log" -delete

6. 快速查看文件

head -n 20 file.txt    # 前 20 行
tail -f log.txt        # 实时追踪日志
less file.txt          # 分页查看

7. 进程管理

top                    # 实时进程监控
ps aux | grep process  # 查找进程
kill -9 PID           # 强制终止
pkill process_name    # 按名称终止

8. 磁盘使用分析

df -h                  # 磁盘空间
du -sh *               # 目录大小
ncdu                   # 交互式磁盘分析

9. 网络诊断

curl -I url           # 查看响应头
ping host             # 连通性测试
netstat -tlnp         # 端口监听
ss -tlnp              # 更快的 netstat

10. tmux 终端复用

tmux new -s session   # 新建会话
tmux attach -t session # 附加会话
Ctrl+b d              # 分离会话

掌握这些技巧,命令行操作效率翻倍!

评论 0

最热最新
暂无评论
匿名用户Lv.1
0
影响力
0
文章
0
粉丝