Run Linux commands and tools on Windows through WSL, enabling a mixed Windows + Linux workflow. Suitable for developer users and scenarios that require Linux tools.
Use Cases
- The user says "use Linux grep to search" or "run a script in WSL"
- Need to use Linux-specific command-line tools (awk, sed, grep, curl)
- Need to manage WSL distributions
- Need to interact between the Windows and Linux file systems
Command Reference
WSL Management
# 查看已安装的发行版
wsl --list --verbose
View installable distributions
wsl --list --online
Install a distributionwsl --install -d Ubuntu
Set the default distributionwsl --set-default Ubuntu
Shut down all WSL instanceswsl --shutdown
View the WSL versionwsl --version
### 执行 Linux 命令
```powershell
# 执行单个命令
wsl ls -la /home
# 指定发行版执行
wsl -d Ubuntu -- ls -la
# 执行带管道的命令
wsl -- cat /etc/os-release | grep -i version
# 在当前 Windows 目录下执行 Linux 命令
wsl -- find . -name "*.py" -type f | wsl -- wc -l
Windows ↔ Linux File Interaction
# 从 Windows 访问 Linux 文件
explorer.exe \\wsl$\Ubuntu\home\user
# 在 WSL 中访问 Windows 文件
wsl -- ls /mnt/c/Users/$env:USERNAME/Documents
# 复制文件:Windows → Linux
wsl -- cp /mnt/c/Users/$env:USERNAME/Desktop/data.csv /home/user/
# 复制文件:Linux → Windows
wsl -- cp /home/user/result.txt /mnt/c/Users/$env:USERNAME/Desktop/
Common Linux Tools (via WSL)
# 文本搜索(grep 比 findstr 强大得多)
wsl -- grep -rn "pattern" /mnt/c/Users/$env:USERNAME/Projects/
# 文本处理
wsl -- awk -F',' '{print $1, $3}' /mnt/c/path/to/data.csv
# JSON 处理
wsl -- cat /mnt/c/path/to/config.json | wsl -- jq '.key.subkey'
# 批量重命名(find + rename)
wsl -- find /mnt/c/path -name "*.txt" -exec rename 's/old/new/' {} \;
# 磁盘使用(比 PowerShell 的 Get-ChildItem 更快)
wsl -- du -sh /mnt/c/Users/$env:USERNAME/* 2>/dev/null | sort -rh | head -10
Development Toolchain
# 在 WSL 中运行 Python
wsl -- python3 /mnt/c/scripts/process.py
# 在 WSL 中运行 Node.js
wsl -- node /mnt/c/project/server.js
# 在 WSL 中使用 Docker
wsl -- docker ps
wsl -- docker-compose up -d
Path Conversion
| Windows Path | WSL Path |
|---|---|
C:\Users\name |
/mnt/c/Users/name |
D:\Data |
/mnt/d/Data |
| Inside WSL | \\wsl$\Ubuntu\home\user |
Output Specifications
- Output execution results as-is (Linux command style)
- When paths involve Windows/Linux conversion, explain both paths
- After a management command is executed, display the current status
Security Rules
- Do not execute
rm -rf /or similar dangerous commands - Do not modify WSL system files(
/etc/key configuration under ) - Deletion operations must be confirmed via HITL
- When WSL is not installed, prompt the user with the installation method (
wsl --install)