Skip to content

Instantly share code, notes, and snippets.

@myinusa
Last active December 2, 2025 12:04
Show Gist options
  • Select an option

  • Save myinusa/c5921f56c668678e112f995197da668a to your computer and use it in GitHub Desktop.

Select an option

Save myinusa/c5921f56c668678e112f995197da668a to your computer and use it in GitHub Desktop.
Copy as Linux Path on Windows 11 (WSL-style `/mnt/c/...`)

“Copy as Linux Path” on Windows 11 (WSL-style /mnt/c/...)

Small quality-of-life thing: on Windows you can copy a file/folder path, but it looks like this:

C:\Users\you\projects

If you’re working with WSL, Docker, or Linux tools, it’s nicer as:

/mnt/c/Users/you/projects

This guide adds a right-click context menu entry in File Explorer called:

Copy as Linux Path

When you click it on a file, folder, or empty space in a folder, it copies a WSL-style path to the clipboard.


What this does (and doesn’t do)

It does:

  • Add three context-menu items (file, folder, background)

  • Call a PowerShell script that:

    • Converts C:\something/mnt/c/something
    • Handles drive roots (C:\/mnt/c)
    • Handles UNC paths (\\server\share\foo/mnt/unc/server/share/foo)
    • Copies the result to the clipboard

It does not:

  • Change file associations
  • Touch boot settings or system services
  • Modify anything outside the shell keys in the registry

If you remove the registry keys, it’s gone.


Requirements

  • Windows 10/11
  • PowerShell (built in)
  • Admin rights (to import the .reg file)
  • Any text editor

I’ll assume we’re using this folder for the script:

C:\Scripts\

Feel free to change that, just keep the .reg file in sync.


1. Create the PowerShell script

Create a file:

C:\Scripts\CopyAsLinuxPath.ps1

Paste this inside:

param(
    [string[]]$TargetPath
)

function Convert-ToLinuxPath {
    param(
        [string]$Path
    )

    if (-not $Path) {
        return $null
    }

    try {
        # Normalize to a full path when possible
        $normalized = [System.IO.Path]::GetFullPath($Path)
    }
    catch {
        # If GetFullPath fails (weird input), just use whatever we got
        $normalized = $Path
    }

    # UNC paths: \\server\share\folder → /mnt/unc/server/share/folder
    if ($normalized.StartsWith("\\\")) {
        $trimmed = $normalized.TrimStart("\")
        $rest = $trimmed -replace '\\','/'
        return "/mnt/unc/$rest"
    }

    # Drive-letter paths: C:\something → /mnt/c/something
    if ($normalized -match '^(?<drive>[A-Za-z]):\\(?<rest>.*)$') {
        $drive = $Matches['drive'].ToLower()
        $rest  = $Matches['rest'] -replace '\\','/'

        if ([string]::IsNullOrEmpty($rest)) {
            # Root of drive, e.g. C:\
            return "/mnt/$drive"
        }
        else {
            return "/mnt/$drive/$rest"
        }
    }

    # Fallback: just swap slashes
    return ($normalized -replace '\\','/')
}

# If nothing was passed, fall back to the current directory
if (-not $TargetPath -or $TargetPath.Count -eq 0) {
    $TargetPath = @(Get-Location)
}

$linuxPaths = @()

foreach ($p in $TargetPath) {
    $lp = Convert-ToLinuxPath -Path $p
    if ($lp) {
        $linuxPaths += $lp
    }
}

if ($linuxPaths.Count -gt 0) {
    $text = $linuxPaths -join "`r`n"
    try {
        Set-Clipboard -Value $text
    }
    catch {
        # Worst case: clipboard fails, we just swallow it
    }
}

Save the file.

If you put this somewhere else, remember the full path; we’ll need it in the next step.


2. Create the registry file

Create another file somewhere (Desktop is fine):

Add_CopyAsLinuxPath.reg

Paste this:

Windows Registry Editor Version 5.00

; ----- File right-click: Copy as Linux Path -----
[HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%1\""

; ----- Folder right-click: Copy as Linux Path -----
[HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%1\""

; ----- Background right-click (inside a folder): Copy as Linux Path -----
[HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath]
@="Copy as Linux Path"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath\command]
@="powershell.exe -NoProfile -ExecutionPolicy Bypass -File \"C:\\Scripts\\CopyAsLinuxPath.ps1\" \"%V\""

If your script isn’t in C:\Scripts\CopyAsLinuxPath.ps1, update all three paths accordingly.


3. (Optional but smart) Export a tiny backup

If you’re nervous about the registry (fair), do this:

  1. Press Win + R, type regedit, hit Enter.

  2. Go to:

    • HKEY_CLASSES_ROOT\*\shell
    • HKEY_CLASSES_ROOT\Directory\shell
    • HKEY_CLASSES_ROOT\Directory\Background\shell
  3. Right-click each shell key → Export → save somewhere as a backup.

If you ever want to revert, you can just double-click those backups.


4. Import the context menu entry

  1. Double-click Add_CopyAsLinuxPath.reg.
  2. Say Yes to the UAC and registry prompts.
  3. That’s it. You don’t need to reboot or log out.

5. Test it

Open File Explorer and try three things:

  1. Right-click a folder → “Copy as Linux Path”

    • Paste somewhere (Notepad, VS Code, etc.)
    • Expected: something like /mnt/c/Users/you/SomeFolder
  2. Right-click a file → “Copy as Linux Path”

    • Expected: /mnt/c/Users/you/SomeFolder/file.txt
  3. Right-click on empty space inside a folder → “Copy as Linux Path”

    • Expected: path to that folder as /mnt/...

If you get a PowerShell error popup instead, it’s usually:

  • The script path in the .reg file doesn’t match where the script actually is.
  • Or the script had a copy/paste issue (missing quote, etc.).

Fix the path or re-paste the script and try again.

image

6. How to remove everything

If you don’t want this anymore, you can nuke it cleanly.

A. Remove the registry keys

Create a file:

Remove_CopyAsLinuxPath.reg

Paste this:

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\*\shell\CopyAsLinuxPath]
[-HKEY_CLASSES_ROOT\Directory\shell\CopyAsLinuxPath]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\CopyAsLinuxPath]

Save → double-click → confirm.

The “Copy as Linux Path” entries will disappear from the context menu.

B. Delete the script (optional)

Just delete:

C:\Scripts\CopyAsLinuxPath.ps1

Done.


7. Notes / Edge cases

  • Drive roots C:\/mnt/c D:\/mnt/d

  • Network paths \\server\share\folder/mnt/unc/server/share/folder This isn’t an official WSL standard, but it’s a reasonable convention and easy to tweak in the script if you want something else.

  • Weird input The script tries GetFullPath() but catches errors. Worst case, it just swaps backslashes for forward slashes.

  • Multiple items The script can handle multiple paths (it joins them with newlines), but the default context menu wiring here passes one item. If you want to wire it up for multi-select in a different way later, the script is already ready for it.


8. Tweaks (if you want to get fancy)

You can modify the PowerShell script to:

  • Show a toast / popup with the copied path.
  • Automatically open WSL with that path.
  • Format paths for Docker volumes, etc.

But the base setup above should be safe, simple, and GitHub-gist-friendly.


That’s it. Drop this into a gist and you’ve got a handy little “Copy as Linux Path” helper for Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment