Say that my username in Windows is "John" (C:\Users\John"
)
My username in WSL Ubuntu is then probably "john" (/home/john
). I say probably as I think WSL lets you pick a name, but I will always pick the same name as my Windows account so this is not an issue for me.
I want to programmatically find the Windows folder from inside WSL. So I know that the Users folder in Windows is at /mnt/c/Users
and I know that my WSL name is john
, but I don't know if the Windows name is john
or John
or JOHN
etc. Linux is rigid in case-sensitivity (this is one area that I think that Microsoft made a brilliant decision for the future - being ultra rigid about case-sensitivity will remain a hassle for decades to come) so I cannot just say /mnt/c/users/john
as that will fail if the name is not exactly john
with that case-sensitivity.
Is there a way that I could look for /mnt/c/users/john
and instruct Linux to just find any path that matches anything like that, no matter the case used ? The brilliant part of the Windows / PowerShell way is that you are case-insensitive by default and can still just turn sensitivity on whenever you need that. I get why they did it in the early days, but I've never ever seen a situation where allowing directories like stuff
, Stuff
, STUFF
, stUff
all to be able to co-exist in the same location as distinct objects has even been of value (in the real world - rigid case-sensitivity is well past its sell by date).
Try the following:
find /mnt/c/Users -maxdepth 1 -type d -regextype posix-extended -regex '/mnt/c/Users/([Jj][Oo][Hh][nN])'
Use find and a regular expression that searches for combination of upper or lower case combinations.
This can alternatively be done with -iregex which represents a case insensitive regular expression search:
find /mnt/c/Users -maxdepth 1 -type d -regextype posix-extended -iregex '/mnt/c/Users/john'