Linux Shell 与常用终端命令
常用文件与环境变量命令
Section titled “常用文件与环境变量命令”| 命令 | 说明与示例 |
|---|---|
echo |
输出字符串或变量值,例如 echo $PATH |
export |
设置或查看环境变量:export -p 列出环境变量;export MYENV=1 定义变量 |
cat |
查看文件内容,如 cat /etc/shells |
alias |
设置命令别名:alias ll='ls -la' |
touch |
更新文件时间戳;若文件不存在则创建空文件:touch file |
dirname |
提取路径中的目录部分,如 dirname /a/b/c.txt 输出 /a/b |
zip |
递归压缩目录:zip -q -r archive.zip dir |
unzip |
解压到指定目录:unzip archive.zip -d target_dir |
Shell 查看与切换
Section titled “Shell 查看与切换”# 查看当前正在使用的 Shellecho $0
# 查看系统已安装的所有合法 Shellcat /etc/shells
# 查看 zsh 路径which zsh
# 将系统默认 Shell 修改为 bashchsh -s /bin/bash端口占用排查与快速编译
Section titled “端口占用排查与快速编译”# 查看指定端口(如 5554)对应的监听进程与 PIDnetstat -tulpn | grep 5554
# 强制结束指定 PID 进程sudo kill -9 <PID>
# C++11 快速单文件编译并运行g++ -std=c++11 -o a a.cpp && ./a