将 Unix/Linux 命令转换为 PowerShell 等效命令的对照工具
Access rate limit exceeded. Please log in to continue.
Linux/Unix to PowerShell Command Alias Migration
Overview
This project configures aliases in PowerShell $PROFILE to help users move from Unix/Linux shells to PowerShell. It defines functions and aliases that map common Linux/Unix commands (such as ls, rm, rmdir, cat) to equivalent PowerShell cmdlets. It also provides interactive hints and recommended PowerShell usage to reduce command conflicts and unsafe operations.
Core Features
- Map Linux/Unix commands to PowerShell cmdlets.
- Show recommended aliases and PowerShell equivalents automatically.
- Extensible design for adding more command hints.
- Keep familiar command behavior for both scripts and interactive usage.
- Smart Unix-style argument handling:
ls -lamaps toGet-ChildItem -Forcels -amaps to hidden-file listingcp -rmaps toCopy-Item -Recurserm -rfmaps toRemove-Item -Recurse -Forcemkdir -psupports parent directory creationmkdir {dir1,dir2,dir3}supports brace expansion
- Enhanced safety checks for risky patterns like
rm -rfwith non-blocking warnings. - Automatic conversion from Unix arguments to PowerShell equivalents.
- Built-in help command:
helpunix <command>. - Windows Environment Integration:
- Automatic Java, Maven, Node.js (nvm4w), and uv environment setup
- Intelligent hints for modern development tools
Get-DevEnvironmentInfofor quick environment overview
- Development Tool Support:
- Node.js/npm with modern alternatives suggestions (bun, deno, pnpm, yarn)
- Python/pip with uv workflow recommendations
- Git shortcuts (gs, ga, gc, gp)
- Navigation aliases (cdcode, cdhome)
Use Cases
- Linux/Bash users migrating to PowerShell for the first time.
- Developers who want to keep Unix-like habits in PowerShell.
- AI agents that need stable command execution in PowerShell without hanging.
- Teams that want guided command hints in terminals or project environments.
- Windows developers working with Java, Node.js, Python ecosystems.
- Cross-platform development teams needing consistent tooling.
Installation
Method 1: Install Script (Recommended)
Use the bundled install script to copy the profile to the correct location:
# Run the install script
./install.ps1
After installation, restart PowerShell or run . $PROFILE to load the profile immediately.
Method 2: Manual Installation
-
Open PowerShell 7 and check your profile path:
$PROFILEUsually:
/Users/<username>/.config/powershell/Microsoft.PowerShell_profile.ps1 -
Create the profile directory if needed:
New-Item -ItemType Directory -Force /Users/<username>/.config/powershell -
Copy the content of
Microsoft.PowerShell_profile.ps1into your$PROFILEfile. -
Load the profile:
. $PROFILENote:
.is PowerShell's source operator for loading the file into the current session.
Usage Examples
Basic Commands
pwd- show current pathcd ..- change directoryls- list files (supports smart conversion of-la,-a,-l)ls -la- list all files including hidden files (maps toGet-ChildItem -Force)cat file.txt- show file contentps- show processes (ps auxis blocked)kill 1234- stop processmv file1 file2- move filecp file1 file2- copy filecp -r sourcedir destdir- recursive copy (maps toCopy-Item -Recurse)rm file- remove filerm -rf directory- recursive force remove (maps toRemove-Item -Recurse -Force)mkdir dirname- create directorymkdir -p parent/child/grandchild- create directory with parent directoriesmkdir -p packages/{core,aur,fonts,applications,development,multimedia}- create multiple directories with brace expansiontouch newfile- create new filehead file- show first linestail file- show last linesgrep "pattern"- search piped input (grep -Eis blocked)clear- clear screen (recommendsclsorClear-Host)
Development Tools
node --version- JavaScript runtime (shows modern alternatives)npm install- Package manager (suggests pnpm/yarn/bun)python script.py- Python execution (recommends uv workflow)pip install package- Package installer (recommends uv)uv init project- Python project initializationuv add requests- Add Python dependenciesuv run python script.py- Run Python with virtual environment
Utility Functions
Get-DevEnvironmentInfo- Show all development tool versionshelpunix node- Help for Node.js commandshelpunix uv- Help for Python uv commandscdcode- Navigate to Code directorycdhome- Navigate to home directory
Git Shortcuts
gs-git statusga .-git add .gc -m "message"-git commit -m "message"gp-git pushgl-git pull
Additional Network and System Commands
wget url- download file (maps toInvoke-WebRequest)curl url- download file (maps toInvoke-WebRequest)find . -name "*.txt"- find files (maps toGet-ChildItem -Recurse)which command- locate command (maps toGet-Command)df- show disk space (maps toGet-PSDrive)du- show directory size (maps toGet-ChildItem | Measure-Object)
Help System
helpunix ls- detailed help forlshelpunix cat- detailed help forcathelpunix rm- safety tips and best practices forrm
Before command execution, the profile prints hints including:
- command style (Unix-like habit vs. PowerShell habit)
- actual alias/cmdlet being executed
- recommended PowerShell usage with common parameter examples
Example for ls:
Unix-Like command 'ls' was called (Unix-style habit)
Actual execution: gci (PowerShell alias) -> Get-ChildItem
Recommended PowerShell usage: gci, Get-ChildItem, gci -fo, Get-ChildItem -Force
Special Argument Handling
Smart Parameter Conversion
ls -la/ls -al/ls -lah/ls -hal->Get-ChildItem -Forcels -a->Get-ChildItem -Force(show hidden files)ls -l-> ignored (PowerShellalready displays long-style output by default)cp -r->Copy-Item -Recurse(recursive copy)cp -f->Copy-Item -Force(force copy)cp -rf->Copy-Item -Recurse -Force(recursive force copy)rm -r->Remove-Item -Recurse(recursive remove)rm -f->Remove-Item -Force(force remove)rm -rf->Remove-Item -Recurse -Force(recursive force remove)mkdir -p->New-Item -ItemType Directory -Force(create parent directories)mkdir {dir1,dir2}-> creates multiple directories from brace expansion
Blocked Argument Patterns
For Unix-style argument combinations that can be misleading in PowerShell, execution is blocked with alternatives:
ps aux->Get-Process | Select-Object ProcessName, Id, CPU, WSgrep -E->Select-String -Pattern "regex"
Safety Protection
Built-in checks detect and warn about dangerous operations:
rm -rf/rm -fr-> dangerous pattern detected, logs warningrm -r -f-> recursive forced deletion detected, logs warningkill -9-> force-kill signal detected, logs warning
When a dangerous operation is detected, the system:
- Shows a warning message
- Logs the operation for audit purposes
- Continues execution automatically (non-blocking for automation)
- Provides PowerShell best-practice guidance
Note: Unlike traditional Unix shells, dangerous commands do not block execution in interactive mode, making this profile ideal for AI agents and automated scripts while still providing safety notifications.
Dangerous Command List
Get-Content,Set-Content,Add-Content,Remove-Item,Clear-Item,Move-Item,Copy-Item,Rename-Item,New-Item,Invoke-Item,Start-Process,Stop-Process,Restart-Process,Get-Process,Stop-Service,Restart-Service,Set-Service,Invoke-Command,Enter-PSSession,New-PSSession,Remove-PSSession,Read-Host,Out-Host,Out-Printer,Format-Table,Format-List,Format-Wide,Format-Custom
This design keeps Unix habits while guiding users to native PowerShell best practices, and provides a stable execution environment for AI agents.