How to Change the Definition of the 'sort' Command in Windows Installer

Abstract: Override Windows Installer's native sort command by placing a custom batch file in a PATH directory that precedes System32.

Created: 2026-08-08 by

You can override the built-in sort command in Windows by creating a batch file named sort.cmd that calls Git Bash. Place this file in a directory that appears earlier in your system PATH than C:\Windows\System32. This ensures your custom script executes instead of the native utility during installation processes.

Understanding the Command Resolution Order

When you type a command into the Windows Command Prompt or PowerShell, the operating system searches for an executable file based on the order defined in the PATH environment variable. The search proceeds from left to right. If you have a directory at the beginning of this list, any executable or batch file placed there will take precedence over files located in standard system directories like C:\Windows\System32. The native sort.exe resides in C:\Windows\System32. To intercept calls to sort, you do not need to modify system files or change registry keys. Instead, you rely on the standard path resolution mechanism. By placing a custom script with the name sort.cmd or sort.bat in a user-controlled directory that is listed first in PATH, you effectively shadow the original command. This technique is commonly used in development environments to ensure tools like Git are utilized over legacy Windows utilities.

Creating the Override Script

The most robust way to replace sort with Git's implementation is to use a batch file that invokes git-bash.exe or directly calls the Git binary. Git provides its own version of coreutils, including sort, which often behaves more consistently across different platforms compared to the Windows native version. Create a new text file and name it sort.cmd. It is critical to use the .cmd extension rather than .bat for modern compatibility, although both work. Open this file in a text editor and add the following content:
@echo off
"C:\Program Files\Git\usr\bin\sort.exe" %*
This script does two things. First, @echo off suppresses the display of the command being executed, keeping the output clean. Second, it calls the actual sort.exe binary provided by Git. The %* placeholder passes all arguments from the original call to the Git executable. This ensures that flags, input files, and redirection operators are handled correctly. If you prefer using the full Git Bash shell for complex scenarios, you could also use:
@echo off
start "" "C:\Program Files\Git\git-bash.exe" -c "sort %*" && exit /b %errorlevel%
However, calling the binary directly is faster and less prone to window pop-ups during automated installations. Note that you must adjust the path to sort.exe if your Git installation is located in a different directory, such as C:\Users\YourName\AppData\Local\Programs\Git.

Configuring the PATH Variable

Once the script is created, you must ensure Windows finds it before the system sort.exe. You need to add the folder containing sort.cmd to the beginning of your PATH variable. 1. Press Win + R, type sysdm.cpl, and press Enter to open System Properties. 2. Click the Advanced tab and select Environment Variables. 3. Under System variables (for all users) or User variables (for your account), find PATH and click Edit. 4. Click New and enter the full path to the directory where you saved sort.cmd. 5. Use the Move Up button repeatedly until this new entry is at the very top of the list. It is important to note that changing the PATH only affects new processes. Existing command prompt windows will continue to use the old path order. You must close and reopen your terminal for the changes to take effect. If you are running an installer that spawns its own command line environment, ensure that environment inherits the updated PATH. Often, installers run in a fresh context, so they will pick up the new definition immediately if the system variable was modified correctly.

Verifying the Change

To confirm that your override is working, open a new Command Prompt window and type:
where sort
The output should show the path to your sort.cmd file first, followed by the system sort.exe further down the list. You can test functionality by piping some text through it:
echo -e "banana\napple\ncherry" | sort
If the output is alphabetically sorted, your configuration is successful. This method allows you to maintain a consistent toolset for scripts that depend on Unix-like sorting behavior, which is particularly useful when working with cross-platform projects or Git repositories. For more details on how Git Bash interacts with Windows Terminal, see our guide on What's the difference between git-bash.exe and bash.exe and how they interact with Windows Terminal?. Additionally, if you encounter issues with batch files due to special characters, check Batch File Not Working with Space in File Name for troubleshooting tips.

Frequently Asked Questions

Will this break other programs that rely on the native sort command?

Most modern applications use their own internal libraries or explicitly call full paths to executables, so they will not be affected. However, older scripts that blindly assume sort is the Windows version might behave differently if they expect specific non-standard outputs. Always test critical workflows after making this change.

How do I revert this change if something goes wrong?

You can simply delete the sort.cmd file or move it out of your PATH directory. Alternatively, remove the custom directory from the top of the PATH variable in Environment Variables. Restarting your computer or opening a new terminal session will restore the default behavior.

Can I do this without modifying the system PATH?

Not easily for global commands. You could create a shortcut or alias in PowerShell, but that only works within that shell. For command-line installers and batch jobs, modifying the PATH is the most reliable method because it applies to all child processes spawned by the system.

Why does my installer still use the old sort command?

The installer process likely started before you changed the PATH or inherited the old environment variables. Ensure you restart the installer application after updating the environment variables. Also, verify that the installer is not hardcoding the path to C:\Windows\System32\sort.exe.

Is it safe to edit files in C:\Windows\System32?

No, you should never replace or rename system files in C:\Windows\System32. Doing so can corrupt your Windows installation and prevent updates from installing correctly. Using the PATH shadowing technique is the safe, supported alternative.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More