Skip to content

caomengxuan666/WinuxCmd

Repository files navigation

WinuxCmd: Linux Commands for Windows × Cross-Shell Pipelines

English | 中文

Native Windows Linux-style commands | ~900KB single binary | No WSL required | Windows commands and Linux-style filters work together

GitHub release (latest by date) GitHub all releases GitHub stars GitHub license Windows Support

Why This Project

WinuxCmd is built for one practical goal: make common Linux command workflows work naturally on Windows terminals.

  • Native Windows executable (winuxcmd.exe), no WSL required
  • Linux-style commands and flags (ls, grep, sed, ps, lsof, ...)
  • Fast startup and small footprint
  • Works well with AI-generated shell commands
  • Cross-tool pipelines between Windows and Linux-style commands

Core Strengths

Feature Value
Windows × Linux pipeline interoperability netstat -ano | grep 8080 works out of the box
Small footprint ~900KB single executable with on-demand links
Fast execution Millisecond-level command execution in common workflows
Smart completion Built-in commands + Windows command whitelist + user-defined entries
Shell-aware fallback Parent shell detection (cmd vs PowerShell/pwsh)

Quick Start

Install (recommended)

irm https://dl.caomengxuan666.com/install.ps1 | iex

Manual install

  1. Download from Releases
  2. Extract to any folder
  3. Enter bin and run:
.\create_links.ps1

Optional:

.\create_links.ps1 -UseSymbolicLinks
.\create_links.ps1 -Remove

Usage Modes

1) Direct command mode

winuxcmd ls -la
winuxcmd grep -n "TODO" README.md
winuxcmd help
winuxcmd help sort

2) Linked command mode

After links are created, you can call commands directly:

ls -la
grep -n "TODO" README.md

Shell-Aware Fallback (cmd / PowerShell)

  • Entered from PowerShell/pwsh: unknown commands fallback through PowerShell
  • Entered from cmd: unknown commands fallback through cmd
  • PowerShell completion entries (for example Get-Process, Where-Object) are enabled only in PowerShell sessions

FFI API

WinuxCmd provides a C Foreign Function Interface (FFI) for integration with other languages and applications.

Available Functions

  • winux_execute() - Execute commands via daemon with zero start-up overhead
  • winux_get_all_commands() - Retrieve all available command names
  • winux_is_daemon_available() - Check if daemon is running
  • winux_get_version() - Get WinuxCmd version string
  • winux_free_buffer() - Free allocated memory
  • winux_free_commands_array() - Free command array allocated by winux_get_all_commands()

Example Usage

#include "ffi.h"

int main() {
    // Check daemon availability
    if (!winux_is_daemon_available()) {
        printf("Daemon not available\n");
        return 1;
    }

    // Get all available commands
    char** commands = NULL;
    int count = 0;
    if (winux_get_all_commands(&commands, &count) == 0) {
        printf("Available commands:\n");
        for (int i = 0; i < count; i++) {
            printf("  %s\n", commands[i]);
        }
        winux_free_commands_array(commands, count);
    }

    // Execute a command
    char* output = NULL;
    char* error = NULL;
    size_t output_size = 0;
    size_t error_size = 0;

    int exit_code = winux_execute("ls", NULL, 0, NULL,
                                  &output, &error,
                                  &output_size, &error_size);

    if (output) {
        fwrite(output, 1, output_size, stdout);
        winux_free_buffer(output);
    }
    if (error) {
        winux_free_buffer(error);
    }

    return 0;
}

Building with FFI

See examples/ffi/ffi_example.c for a complete example. The FFI library (winuxcore.dll) is built when BUILD_FFI=ON is set.

PowerShell Auto-Enter (Interactive)

Add this to your PowerShell profile ($PROFILE) to auto-enter WinuxCmd for interactive terminal sessions:

# Automatically entering winuxcmd REPL env.
$cliArgs = [Environment]::GetCommandLineArgs() | ForEach-Object { $_.ToLowerInvariant() }
$isNonInteractiveLaunch = ($cliArgs -contains '-command') -or ($cliArgs -contains '-c') -or ($cliArgs -contains '-file') -or ($cliArgs -contains '-f')
$isRealTerminal = $env:WT_SESSION -or $env:TERM_PROGRAM
if ($Host.Name -eq 'ConsoleHost' -and -not $isNonInteractiveLaunch `
    -and $env:WINUXCMD_BOOTSTRAPPED -ne '1' -and $isRealTerminal) {
    $env:WINUXCMD_BOOTSTRAPPED = '1'
    $winuxExe = (Get-Command winuxcmd -ErrorAction SilentlyContinue).Source
    if (-not $winuxExe) {
        $devExe = 'your\winuxcmd.exe\path'  # replace with your local path
        if (Test-Path $devExe) {
            $winuxExe = $devExe
        }
    }
    if ($winuxExe -and (Test-Path $winuxExe)) {
        & $winuxExe
    }
}

Replace $devExe with the actual local path to your winuxcmd.exe.

Entering WinuxCmd from cmd (Interactive)

Using a registry AutoRun hook for cmd is risky: it also affects background usages such as cmd /c and Run dialog launches, and can force unexpected interactive WinuxCmd sessions.

Recommended approach:

  • If you entered from plain cmd, manually run winuxcmd to enter the completion-enabled interactive environment.
  • Avoid cmd AutoRun registry hooks: they also affect non-interactive/background calls such as cmd /c.
  • Prefer Windows Terminal, and launch cmd with:

%SystemRoot%\System32\cmd.exe /k winuxcmd

Windows Terminal

Completion and Environment Variables

WinuxCmd supports user-defined completion entries.

Auto Completion Demo

  • Default file: %USERPROFILE%\.winuxcmd\completions\user-completions.txt
  • Override path via env var: WINUXCMD_COMPLETION_FILE

Example format:

cmd|git|Distributed version control
opt|git|pull|Fetch from and integrate with another repository

Template file:

  • scripts/user-completions.sample.txt

Pipeline Examples

netstat -ano | grep 8080
tasklist | grep -i chrome
ipconfig | grep -i "ipv4"
ps -ef | grep winuxcmd

Implemented Commands

137 commands are currently implemented. See full compatibility and option details:

Performance Comparison

Full execution benchmark (startup + execution + exit), 1000-file directory, 20 runs per command.

Command WinuxCmd (ms) uutils (Rust) (ms) Winner
ls 6.30 7.27 WinuxCmd
cat 6.19 7.01 WinuxCmd
head 6.27 6.79 WinuxCmd
tail 6.34 6.84 WinuxCmd
grep 6.42 5.99 uutils
sort 6.31 7.27 WinuxCmd
uniq 6.23 6.84 WinuxCmd
wc 6.21 6.81 WinuxCmd

Summary:

  • WinuxCmd wins in 7/8 commands
  • Average time: WinuxCmd 6.28ms vs uutils 6.85ms
  • Overall: about 1.09x faster

Benchmark details and notes:

Roadmap

Phase 1: Core and Compatibility

  • Stabilize Linux-style core commands on Windows
  • Improve REPL fallback correctness for cmd/PowerShell
  • Keep binary size and startup performance targets

Phase 2: Shell and Tooling

  • Better completion relevance and ranking
  • More compatibility fixes for mixed Windows/Linux pipelines
  • Improved test coverage for shell-edge scenarios

Phase 3: Ecosystem

  • Better integration docs and templates
  • Contributor tooling and automation improvements
  • Long-term cross-platform abstraction planning

Q&A

Q: Is this a replacement for PowerShell?

A: No. WinuxCmd complements PowerShell. Use whichever syntax is best for the task.

Q: Why do some commands fallback to cmd or PowerShell?

A: Unknown commands are intentionally routed to the parent shell environment for compatibility.

Q: Can I customize completion entries?

A: Yes. Use %USERPROFILE%\.winuxcmd\completions\user-completions.txt or set WINUXCMD_COMPLETION_FILE.

Q: Why does output sometimes show access-denied warnings (for example in lsof)?

A: Windows handle/process visibility depends on privilege level. WinuxCmd degrades gracefully and reports partial-result warnings instead of crashing.

Project Characteristics

  • Many users in daily usage scenarios
  • Limited contributor capacity
  • Strong need for focused, high-quality contributions

If you want to help, the most valuable areas are:

  1. Bug fixes for shell compatibility
  2. Test coverage for REPL/fallback behavior
  3. Documentation clarity and examples

Contributing

Documentation

License

MIT License (c) 2026 caomengxuan666. See LICENSE.

About

Lightweight, native Windows implementation of Linux commands | 1MB only | AI-friendly

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors