Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path to the Windows user's home directory (/mnt/c/Users/username) from within WSL?

I need to get the path to the Windows user's home directory /mnt/c/Users/username from within WSL, is it stored somewhere?

If not, is username stored somewhere? I'll just assume the /mnt/c/Users part doesn't change.

Thanks!

like image 409
ZYinMD Avatar asked Oct 17 '25 18:10

ZYinMD


2 Answers

vGet it using cmd.exe and parse it to WSL path using wslpath (requires an updated WSL with wslpath installed):

Bash

WIN_HOME_RAW="$(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)"
WIN_HOME="$(wslpath $WIN_HOME_RAW)"

Fish

set WIN_HOME_RAW (cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null)
set -gx WIN_HOME (wslpath $WIN_HOME_RAW)
like image 200
idanp Avatar answered Oct 19 '25 12:10

idanp


You may simply use wslpath and wslvar together as below:

$ wslpath "$(wslvar USERPROFILE)"

which will return something like this:

/mnt/c/Users/{USERNAME}

like image 32
Pmpr.ir Avatar answered Oct 19 '25 13:10

Pmpr.ir