---
title: "开发工具命令"
canonical_url: "https://wwlight.vercel.app/guides/system/dev-tools-commands"
---
# 开发工具命令

## 跨平台通用工具

### adb

<tip to="https://developer.android.com/tools/adb">

Android 官方命令行调试工具，可通过 USB 或 WiFi 无线连接手机。

</tip>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install adb
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install --cask android-platform-tools
```

</tabs-item>
</tabs>

```bash
$ adb tcpip 5555

# 查看手机 ip
$ adb shell ifconfig wlan0

# 连接手机
$ adb connect 192.168.xx.xxx

# 断开连接
$ adb disconnect 192.168.xx.xxx

# 其他
$ adb kill-server
```

### code-server

<tip to="https://github.com/coder/code-server">

VS Code 的服务器版本，可在浏览器中远程访问，适合本地部署。

</tip>

- 配置路径：`~/.config/code-server/config.yaml`

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ npm install -g code-server
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install code-server
$ brew uninstall code-server
$ brew info code-server              # 显示 code-server 信息
$ brew services start code-server
$ brew services stop code-server
$ brew services restart code-server

# 直接运行
$ code-server
$ code-server start
$ code-server restart
$ code-server info                   # 查看基本信息

# 同步本地 VSCode 配置
$ ln -s ~/.vscode/extensions ~/.local/share/code-server

$ ln -s ~/.config/Code/User ~/.local/share/code-server
# 若没有 ~/.config/Code/User 文件，执行
$ ln -s ~/Library/Application\ Support/Code/User ~/.local/share/code-server

$ ln -s ~/.config/Code/Backups ~/.local/share/code-server
# 若没有 ~/.config/Code/Backups 文件，执行
$ ln -s ~/Library/Application\ Support/Code/Backups ~/.local/share/code-server
```

</tabs-item>
</tabs>

### syncthing

<tip to="https://syncthing.net/">

开源的点对点文件同步工具，无需中央服务器。

</tip>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install syncthing
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install syncthing
```

</tabs-item>
</tabs>

```bash [命令]
$ syncthing -h
$ syncthing -paths        # 检查默认配置路径
```

### ngrok

<tip to="https://ngrok.com/">

内网穿透工具，为本地服务生成公网可访问的临时地址。

</tip>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install ngrok
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install ngrok
```

</tabs-item>
</tabs>

```bash [命令]
$ ngrok http http://localhost:8080
```

### uv

<tip to="https://github.com/astral-sh/uv">

用 Rust 编写的极速 Python 包与项目管理工具。

</tip>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install uv
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install uv
```

</tabs-item>
</tabs>

```bash [zsh 补全配置]
echo 'eval "$(uv generate-shell-completion zsh)"' >> ~/.zshrc
echo 'eval "$(uvx --generate-shell-completion zsh)"' >> ~/.zshrc
source ~/.zshrc
```

```bash [命令]
# 安装 python，uv 能检测系统上已经安装并使用安装的 Python
$ uv python install

# 查看可用的或已安装的 Python 版本
$ uv python list

# 初始化一个新项目，目录下会生成 `pyproject.toml`、`.python-version` 文件
$ uv init

# 创建虚拟环境
$ uv venv

# 下载依赖项并添加到项目中
$ uv add

# 查看项目的依赖关系树
$ uv tree

# 从项目中删除依赖项
$ uv remove
```

### mysql

<tip to="https://dev.mysql.com/">

最流行的开源关系型数据库管理系统，支持 macOS / Linux / Windows。

</tip>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install mysql
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install mysql
$ brew uninstall mysql
$ brew info mysql                    # 显示 MySQL 信息
$ brew services start mysql          # 启动 MySQL 服务
$ brew services stop mysql           # 停止 MySQL 服务
$ brew services restart mysql        # 重启 MySQL 服务
$ mysql.server start                 # 临时启动 MySQL
$ mysql.server stop                  # 停止临时运行的 MySQL
```

```bash [启动问题排查]
# 查看日志
$ tail -f /opt/homebrew/var/mysql/$(hostname).err

$ brew services stop mysql
$ rm -f ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# 停止所有 mysql 进程
$ ps aux | grep mysqld
$ sudo pkill -9 mysqld

# 设置权限
brew services stop mysql
pkill -9 -f mysqld
sudo mkdir -p /opt/homebrew/var/mysql
sudo chown $(whoami):admin /opt/homebrew/var/mysql
mysqld --initialize-insecure --user=$(whoami) --basedir="$(brew --prefix mysql)" --datadir=/opt/homebrew/var/mysql --tmpdir=/tmp

# 重新启动
$ brew services reload mysql
```

</tabs-item>
</tabs>

```bash [命令]
$ mysql -u root                      # 以默认用户登录 MySQL
$ mysql -u root -p                   # 以默认用户密码登录 MySQL
$ mysql_secure_installation          # 初次安装后设置 root 用户的密码
$ mysql --version                    # 查看 MySQL 版本
```

### nginx

<tip to="https://nginx.org/">

高性能的 HTTP 服务器与反向代理服务器，支持 macOS / Linux / Windows。

</tip>

<warning>

请勿混用 `nginx` 命令和 `brew services` 管理 nginx。两者混用会导致：

- 产生未被 launchd 管理的残留进程，占用端口
- `brew services start nginx` 因端口冲突而失败

选择一种方式并保持一致：推荐始终使用 `brew services`（launchd 托管，开机自启），避免使用 `nginx` 命令临时运行。

</warning>

<tabs sync="os">
<tabs-item label="Windows">

```bash
$ scoop install nginx
```

</tabs-item>

<tabs-item label="MacOS">

```bash
$ brew install nginx
$ brew info nginx                        # 显示 nginx 信息
$ brew services start nginx              # 启动 nginx 服务
$ brew services stop nginx               # 停止 nginx 服务
$ brew services restart nginx            # 重启 nginx 服务（修改配置后）
$ brew services list | grep nginx        # 查看服务状态

# 卸载
$ brew uninstall nginx
$ rm -rf /opt/homebrew/etc/nginx         # 删除配置文件
```

```bash [启动失败排查]
# 检查端口是否被占用（默认 8888）
$ lsof -i :8888

# 查看错误日志
$ tail -20 /opt/homebrew/var/log/nginx/error.log

# 如果有残留的 root 进程，先杀掉
$ ps aux | grep nginx                    # 找到残留进程 PID
$ sudo kill -QUIT <pid>                  # 安全关闭
# 或：sudo pkill -f nginx               # 关闭所有 nginx 进程

# 清理后重新启动
$ brew services restart nginx

# 权限修复（如遇 Permission denied）
$ sudo mkdir -p /opt/homebrew/var/run
$ sudo chown -R $(whoami):admin /opt/homebrew/var/run
$ sudo chmod 755 /opt/homebrew/var/run
$ sudo chown -R $(whoami):admin /opt/homebrew/var/log/nginx
$ sudo chmod -R 755 /opt/homebrew/var/log/nginx
```

</tabs-item>
</tabs>

```bash [命令]
# 配置检查
$ nginx -t                               # 检查配置文件是否正确
$ nginx -s reload                        # 重新加载配置文件（修改配置后，无需重启）

# 查看
$ nginx -v                               # 查看 nginx 版本
$ nginx -V                               # 查看完整的 nginx 编译参数
$ ps aux | grep nginx                    # 查看所有 nginx 进程

# 临时运行（不推荐，建议使用服务管理）
$ nginx                                  # 手动启动
$ nginx -s stop                          # 停止临时运行的 nginx
$ nginx -s quit                          # 安全关闭临时运行的 nginx
```

### netstat

<tip to="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netstat">

（Network Statistics）显示网络连接、路由表、接口统计等信息。

</tip>

```bash
-a  显示所有连接和监听端口
-n  以数字形式显示地址和端口号
-p  显示进程ID/名称（Linux）/协议类型（Windows）
-r  显示路由表
-s  显示每个协议的统计信息

# windows 特有
-o  显示拥有每个连接的进程ID
-b  显示创建每个连接或监听端口的可执行文件

# 查看所有活动连接
$ netstat -ano
# 查看特定端口的占用情况
$ netstat -ano | findstr :80
# 只查看TCP连接
$ netstat -ano -p tcp
# 查看路由表
$ netstat -r
```

## Windows 专属

### Powershell

<tip to="https://learn.microsoft.com/en-us/powershell/">

微软现代的自动化脚本和配置管理框架。

</tip>

```sh
$ E:                     # 切换盘符
$ systeminfo             # 显示完整的系统信息
$ $PROFILE               # 配置文件地址
$ $PSVersionTable        # 查看版本
$ (Get-Host).Version     # 查看版本
$ dir                    # 查看当前目录内容
$ dir ad                 # 仅查看文件夹
$ tree                   # 以树状图显示目录结构
$ $psversiontable        # 查看版本
$ get-ExecutionPolicy
$ set-ExecutionPolicy RemoteSigned
```

### Cmd

<tip to="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd">

Windows 传统命令行解释器。

</tip>

```sh
$ E:                     # 切换盘符
$ E: & \directory        # 直接切换到其他盘符的某个目录
$ cd /d D:\directory     # 强制切换
$ systeminfo             # 显示完整的系统信息
$ ver                    # 查看版本
$ dir                    # 查看当前目录内容
$ dir ad                 # 仅查看文件夹
$ tree                   # 以树状图显示目录结构
```

### tasklist

<tip to="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/tasklist">

显示本地计算机或远程计算机上当前正在运行的进程列表。

</tip>

```bash
$ tasklist /?
$ tasklist | findstr "nginx"
```

### taskkill

<tip to="https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill">

结束一个或多个任务或进程。可以按进程 ID 或映像名称来结束进程。

</tip>

```bash
$ taskkill /?
$ taskkill /F /IM nginx.exe /T
```


## Sitemap

See the full [sitemap](https://wwlight.vercel.app/sitemap.md) for all pages.
