wsl-for-linux
v1.1.0
Published
让 Linux 也能运行 WSL 的命令行工具
Readme
WSL for Linux https://badge.fury.io/js/wsl-for-linux.svg https://img.shields.io/badge/License-MIT-yellow.svg https://img.shields.io/badge/PRs-welcome-brightgreen.svg
让 Linux 也能运行 WSL 的命令行工具 🐧✨
一个用 C 语言编写的轻量级命令行工具,让 Linux 用户也能体验 Windows Subsystem for Linux (WSL) 的命令语法和功能。无需虚拟化,原生运行,性能提升 100%!
✨ 特性 🚀 零虚拟化开销 - 原生运行在 Linux 上,性能最优
🎯 完整 WSL 兼容 - 支持所有常用 WSL 命令选项
📦 零依赖 - 纯 C 实现,只需要 GCC 编译
⚡ 极速启动 - 毫秒级启动,无需等待虚拟机
🔧 简单易用 - npm 一键安装,开箱即用
🎨 友好输出 - 彩色终端输出,清晰直观
📦 安装 前置要求 Linux 系统(任何发行版)
GCC 编译器(或 Clang)
Node.js 和 npm(用于安装)
通过 npm 安装(推荐) bash
全局安装
npm install -g wsl-for-linux 从源码编译 bash
克隆仓库
git clone https://github.com/0x1a27/wsl-for-linux.git cd wsl-for-linux
编译
gcc -o wsl wsl.c
安装到系统路径
sudo mv wsl /usr/local/bin/wsl 使用 Makefile bash
编译
make
安装
sudo make install
卸载
sudo make uninstall
清理
make clean 🚀 快速开始 bash
启动 WSL(进入交互式 shell)
wsl
查看版本信息
wsl --version
查看运行状态
wsl --status
列出已安装的分发
wsl --list
执行命令
wsl echo "Hello from WSL on Linux!" wsl ls -la wsl python3 --version
关闭 WSL
wsl --shutdown
查看帮助
wsl --help 📖 命令选项 命令 简写 描述 wsl - 启动交互式 shell wsl --help -h 显示帮助信息 wsl --version -v 显示版本信息 wsl --status -s 显示 WSL 状态 wsl --list -l 列出已安装的分发 wsl --shutdown - 关闭 WSL wsl - 执行指定命令 💡 使用示例 基本使用 bash
查看版本
$ wsl --version WSL 版本: 2.0.0 内核版本: Linux 6.8.0-generic 分发版本: Linux-Native 系统架构: x86_64 Shell: /bin/bash 说明: 此 WSL 运行在原生 Linux 上,性能最优
查看状态
$ wsl --status 默认分发: Linux-Native WSL 版本: 2.0.0 运行状态: ✅ 运行中 虚拟化: 无(原生模式) 性能: 100%(无虚拟化开销) 兼容性: 完美(因为本来就是 Linux) 执行命令 bash
简单命令
$ wsl ls -la ✅ WSL 已在 Linux 上成功启动! 正在初始化 Windows 子系统... 检测到当前系统就是 Linux,跳过虚拟化... 直接进入 Linux 环境... 执行命令: ls -la
total 48 drwxr-xr-x 6 user user 4096 Feb 23 10:00 . drwxr-xr-x 18 user user 4096 Feb 23 10:00 ..
管道命令
$ wsl ls | grep ".txt" file1.txt file2.txt
复杂命令
$ wsl bash -c "echo 'Hello' && echo 'World'" Hello World 脚本集成 bash #!/bin/bash
在脚本中使用 WSL
result=$(wsl ls -la) echo "WSL 执行结果: $result"
条件判断
if wsl test -f /etc/passwd; then echo "文件存在" fi
循环使用
for i in {1..5}; do wsl echo "Iteration $i" done CI/CD 集成 yaml
.github/workflows/test.yml
name: Test with WSL
on: [push]
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install WSL
run: npm install -g wsl-for-linux
- name: Run tests
run: |
wsl echo "Running tests in WSL..."
wsl npm testDocker 集成 dockerfile
Dockerfile
FROM ubuntu:24.04
RUN apt-get update &&
apt-get install -y gcc nodejs npm &&
npm install -g wsl-for-linux
CMD ["wsl"] 🔧 配置 环境变量 bash
设置默认 shell
export WSL_SHELL=/bin/zsh
设置分发名称
export WSL_DISTRO_NAME="MyCustomDistro"
添加到 ~/.bashrc 或 ~/.zshrc
echo 'export WSL_DISTRO_NAME="Linux-Native"' >> ~/.bashrc Shell 别名 bash
创建别名
alias wslb='wsl bash' alias wslz='wsl zsh' alias wslp='wsl python3'
添加到 shell 配置
echo "alias wslb='wsl bash'" >> ~/.bashrc source ~/.bashrc 🎯 工作原理 WSL for Linux 创建了一个 wsl 命令的兼容层,让 Linux 用户也能使用熟悉的 WSL 命令语法。它的工作原理:
命令解析 - 解析用户输入的 WSL 命令
选项处理 - 识别并处理所有 WSL 选项
命令执行 - 直接调用系统 shell 执行命令
输出格式化 - 格式化输出,模拟 WSL 体验
🤝 贡献 欢迎贡献代码、报告问题或提出建议!
贡献指南 Fork 本仓库
创建特性分支 (git checkout -b feature/AmazingFeature)
提交更改 (git commit -m 'Add some AmazingFeature')
推送到分支 (git push origin feature/AmazingFeature)
打开 Pull Request
开发 bash
克隆仓库
git clone https://github.com/0x1a27/wsl-for-linux.git cd wsl-for-linux
编译调试版本
gcc -g -o wsl wsl.c
运行测试
./wsl --version ./wsl --status ./wsl echo "test" 📝 常见问题 Q: 这个工具真的能运行 Windows 程序吗?
A: 不能。这个工具是让 Linux 用户也能使用 WSL 的命令语法,而不是真的运行 Windows 程序。
Q: 和真实的 WSL 有什么区别?
A: 真实的 WSL 是在 Windows 上运行 Linux,而这个是原生运行在 Linux 上,性能更好。
Q: 需要安装 Windows 吗?
A: 不需要,完全在 Linux 上运行。
Q: 支持哪些 Linux 发行版?
A: 理论上支持所有 Linux 发行版,只要你能编译 C 程序。
Q: 为什么叫 WSL for Linux?
A: 这是一个幽默的项目,让 Linux 用户也能体验 WSL 的命令语法。
Q: 如何卸载?
A: 使用 npm uninstall -g wsl-for-linux 或 sudo make uninstall
🗺️ 路线图 □ 支持更多 WSL 选项 □ 添加配置文件支持 □ 支持自定义分发 □ 添加 GUI 支持 □ 支持 Docker 集成 □ 多语言支持 □ 单元测试 □ Snap/Flatpak 打包 📄 许可证 本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
text MIT License
Copyright (c) 2026 0x1a27
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 🙏 致谢 感谢所有贡献者
感谢 WSL 团队提供的灵感
感谢开源社区的支持
📞 联系方式 作者: 0x1a27
项目: https://github.com/0x1a27/wsl-for-linux
问题: Issues
讨论: Discussions
⭐ 支持项目 如果这个项目对你有帮助,请给个 Star ⭐ 支持一下!
https://api.star-history.com/svg?repos=0x1a27/wsl-for-linux&type=Date
