460

When I start bash on Windows Subsystem for Linux, it drops me in the directory

/mnt/c/Users/<username>

When I ls this directory, I see the directories Desktop, Documents, etc. that I can see are in C:\Users\<username> using the Windows File Explorer. Since this is where the bash program started, I expected this is my home directory, but when I type either cd or cd ~ I am brought to

/home/<username>

which contains my .bashrc, .profile etc. file which I would expect to find in my home directory in a Linux box. Moreover, entering cd ../.. from here I can see the directories bin, etc and so on, again as expected on a Linux box.

I have two questions regarding all this:

  1. What exactly is /mnt/c/Users/<username> compared with C:\Users\<username>? It seems they are one in the same---so what is /mnt/c/?
  2. How can I view the files in /home/<username> using the Windows File Explorer? Not that I'd really ever want to---I'm just trying to get a feel for how Windows is organizing this Subsystem for Linux thing.
magicandre1981
  • 97,301
  • 30
  • 179
  • 245
bcf
  • 4,743
  • 3
  • 12
  • 9
  • 5
    Possible duplicate of [Where is the Linux Subsystem's filesystem located in Windows 10?](https://superuser.com/questions/1067373/where-is-the-linux-subsystems-filesystem-located-in-windows-10) – Jaime Jul 29 '18 at 05:51

11 Answers11

468

In the latest versions [2020], the file system is accessed from:

# \\wsl$\<Distribution>:

\\wsl$\Ubuntu

Previously, as of 2018, The current path is related to which distribution you have installed from the Microsoft Store rather than one global path; for Ubuntu, it was located at:

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

Other distributions should be (to be confirmed) in a similar location under their respective folders within:

%LOCALAPPDATA%\Packages\
Ramhound
  • 41,734
  • 35
  • 103
  • 130
Michael Bond
  • 4,797
  • 1
  • 7
  • 3
  • 62
    Anyone else find this practice disturbing? Isn't my HOME folder supposed to be the ONE safe place for MY data inside a repo? With this approach, a broken repo and reinstall hoses MY DATA with NO attempt to protect it at all AND it's hidden when I already have a REAL /home. Why isn't data persisted there? This is all the more dangerous because we're now being encouraged to try/use/swap distros (WLinux). Really feels like someone didn't think this whole thing through. – rainabba Sep 25 '18 at 19:53
  • In my case (1809) the folder is called CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc – jao Dec 03 '18 at 13:34
  • 11
    Important Note: You should still not poke around Linux files using Windows tools. See: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/#comment-85115 (also see the blog post itself) – coltoneakins Dec 11 '18 at 06:14
  • fantastic. another reason git for windows/mingw still works better... much more thought put into real daily workloads. is there a way to remap it properly? – enorl76 Feb 17 '19 at 05:34
  • 9
    @rainabba At first blush I agree but after some thought, I'm still choosing to use Windows rather than full-blown Ubuntu. As such I'm treating WSL as a way to access Linux tools but still treating my windows file system as the first class citizen. So `/mnt/c/` is where I store everything in WSL. I would love it if WSL was reversed to LWS; meaning it would be awesome if we were all running Ubuntu with Linux Subsystems for Windows to run a complete Windows 10 copy integrated into Ubuntu. I know, that would be a lot harder but one can dream. – CatDadCode Jul 12 '19 at 06:10
  • 26
    For WSL2 you can access to home directory from windows like this \\wsl$ – Francisco Tena Oct 31 '19 at 09:01
  • People said "Do not change anything". Just VSCode WSL plugin will just do fine when you need to edit anything with an GUI IDE. – Jacky Dec 01 '19 at 12:39
  • Thanks, I wanted to know where this folder was because I need to copy my SSH keyfile to this folder and want to make sure it's encrypted so I know which folder to encrypt with EFS. – user324747 Feb 09 '20 at 22:16
  • just noticed that if I copy a file to this location, it doesn't immediately show up in my home directory unless I logout of WSL and then back in. WTF – nont Feb 14 '20 at 18:13
  • 18
    @FranciscoTena fortunately `\\wsl$` is available already for WSL1 since Windows 10 1903! – pabouk - Ukraine stay strong Apr 28 '20 at 20:56
  • I only see a file called: ext4 (about 2GB), is this a virtual hard drive which contains every files in the WSL? – Franva Jun 11 '20 at 02:17
  • 1
    @coltoneakins That's not what the article is saying. They don't want you to LOCK any files in the native files that contains the linux files. Accessing them through \\wsl$\ is perfectly acceptable. – Brain2000 Oct 22 '20 at 16:39
  • So where is this \\wsl$ on my disk? What if I want to move the linux file system in another partition or hard drive? – Thanasis Ioannidis Oct 24 '20 at 11:38
  • @Brain2000 Just for the record: This is an older question that has since been updated. When I added my original comment w/ the article from Microsoft, the `\\wsl$\` path didn't exist. The article has since been updated. – coltoneakins Oct 26 '20 at 17:47
  • 1
    One interesting twist, on this is that as of build 20262 under `%LOCALAPPDATA%\Packages\\LocalState`, you can see a file named `ext4.vhdx` which is the virtual disk file that ends up getting mounted into `\\wsl$`, so theoretically, you could copy that to save its state or mount it via right-click on the file. Mind you I tried mounting it, but because wsl2 is running it says that the file is in use :-). – luv2learn Nov 25 '20 at 18:46
  • An incorrect edit was applied to this answer, `\\wsl.localhost\` only applies to Windows 11, and does not apply to any version of Windows 10. The full path provided in the edit is also not even valid, indicating just ``\\wsl.localhost\` while incorrect, would have been less incorrect. I have reverted the answer to the previous version since this question is about WSL on Windows 10 not Windows 11 – Ramhound Nov 05 '21 at 01:00
  • `\\wsl$` does not work for me, either in the file explorer, either in the command line. But I may miss the correct usage. – lalebarde Mar 02 '22 at 07:46
  • 1
    my path is `\\wsl.localhost\Distro_name` as of 2022 – moth Sep 13 '22 at 14:02
  • @rainabba https://superuser.com/a/1643213/16966 has a short recipe for moving HOME to any arbitrary location. Comments to other answers indicate there may problems with permissions, but following links says there's also an official solution (https://stackoverflow.com/a/50856772/14420) – matt wilkie Mar 22 '23 at 16:04
341

In Bash, to view the current directory in Windows File Explorer just enter:

explorer.exe .

Don't leave out the ".".

This will open windows explorer at the current folder and you can see where everything is in relation to the rest of your Windows system.

Walter A
  • 103
  • 5
Gary Barrett
  • 4,692
  • 3
  • 19
  • 23
  • 40
    Actually `explorer.exe .` does work in WSL. This is the only answer which worked for me as all the paths provided by the other answers are not present in my system. I could not edit the answer myself because _edits must be at least 6 characters_. – Marco Lackovic Dec 10 '19 at 11:07
  • 8
    Interesting. In my case, no matter where I execute `explorer.exe .`, it always open the File Explorer in my Windows user home directory (`%USERPROFILE%`). Windows 10 Enterprise 1809 (build 17763.1039), Ubuntu 18.04. Doesn't matter if I'm in my Ubuntu's home, `/etc` or whatever. – David Ferenczy Rogožan Mar 06 '20 at 18:27
  • 3
    I think we may miscommunicate here - the answer seems to relate to bash itself, right? But not necessarily bash in WSL1. I just tried this on my ubuntu installation within WSL1 and "explorer.exe" can not be found, so I think the answer can only be partially correct, contrary as to what Marco Lackovic stated. Perhaps explorer.exe works, but 100% not by default, because I have just tried it with an instance of bash booting ubuntu. – shevy Aug 26 '20 at 16:25
  • 1
    This worked like charm! I didn't expected that .exe will work from WSL2 terminal. crazy! – Code Cooker Sep 13 '21 at 16:33
  • great answer; C:\Users\\Ubuntu\rootfs\home\ – Craig Wilcox Aug 05 '22 at 18:35
  • To see which directory need to be backed up on windows see what @Coffee_fan mentioned in another answer: *as of build 20262 under %LOCALAPPDATA%\Packages\\LocalState, you can see a file named ext4.vhdx which is the virtual disk file that ends up getting mounted into \\wsl$* where the distro name starts with CanonicalGroupLimited – monok Aug 25 '22 at 09:15
  • 1
    This is the correct answer. You can access the WSL Home directory by doing this as well as pin it to Quick Access. Also see here (https://dev.to/vetswhocode/sharing-your-project-folder-with-windows-and-wsl-cg) for another answer involving aliases and switching directory. – Barra Nov 11 '22 at 21:52
  • 1
    Note: you need to run `explorer.exe .` and not simply `explorer .` (which is what you're probably used to doing in Windows). – jarmod Feb 18 '23 at 20:09
  • 1
    thx, this should be a correct answer – Alex Sham Jun 27 '23 at 17:11
66
  1. /mnt/c is the exact same as C:\. It's just the syntax for getting to it from WSL.
  2. Look in C:\Users\<username>\AppData\Local\Lxss\rootfs.
  • 12
    Warning: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/ that's the place yes but do not change anything. – chx May 05 '17 at 22:34
  • 16
    As of 2018, this answer is not valid anymore. See @MichaelBond's answer. – dr_ Mar 20 '18 at 09:44
  • 46
    Now it's gone to ```C:\Users\[USERNAME]\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_[CODE]\LocalState\rootfs\``` You might aware how bad if you edit ```/``` manually – mementototem Jun 21 '18 at 05:41
  • 3
    for easy access via copy-pasta, `%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_[CODE]\LocalState\rootfs\` – twig May 13 '19 at 00:05
  • 1
    Note that the lxss folder will be hidden in File Explorer unless you uncheck "Folder options > View : Advanced settings : Hide protected operating system files (Recommended)". But even though it's hidden, you can still open the folder in File Explorer if you enter it in the folder path. – Daryn May 16 '19 at 07:20
  • Could someone confirm the new path among the replies? The /mnt/c answer in (1) is still correct; I have not yet tested answer in (2) yet - I am typing this from another machine right now, but am testing on a windows laptop. Already tested (1) which still works - I am scared of (2) not working though ... – shevy Aug 26 '20 at 16:27
51

About the filesystem mounted on /mnt/c

  1. What exactly is /mnt/c/Users/ compared with C:\Users<username>? It seems they are one in the same---so what is /mnt/c/?

In contrast to Windows, Linux (and the other systems based on Unix) use a single folder structure independent of the number of disks you have. If you have multiple disks, all these disks must me mounted into the folder structure at some point.

  • Typically, all the disks (different than the used to boot the system) are mounted in a folder named /mnt or /media

WSL has an special type of filesystem named DrvFS that gives you access to the disks used in windows. You can use DrvFS to mount, not only your windows filesystem, but also network disks and other media types.

  • In WSL, by default, the C: disk in windows is mounted under /mnt/c
  • If you have another disk, for instance a D: disk in windows, it will be mounted under /mnt/d

The files you can see in /mnt/c are the same you have in C:. If you modify some file, you will get the changes in the windows too.

You may use the mount command to access other types of media (e.g. removable drives or network shares).


About the location of /home/<username>

  1. How can I view the files in /home/ using the Windows File Explorer? Not that I'd really ever want to---I'm just trying to get a feel for how Windows is organizing this Subsystem for Linux thing.

In WSL, all the linux filesystem is located under a Windows folder. The location of the folder depends on the version of Windows and of the WSL distribution you are using.

  • Initial versions of WSL store the linux filesystem in %LOCALAPPDATA%\Lxss\rootfs
  • WSL distributions installed from the Windows Store, starting in Windows Build 16215 (mid of 2017), use a folder like %LOCALAPPDATA%\Packages\{package}\LocalState\rootfs. The name of the package varies depending on the distribution (e.g. it is different for Ubuntu than for Debian). For Ubuntu on Windows it is CanonicalGroupLimited.UbuntuonWindows_{code}, for example.
  • Linux distributions installed using other tools, such as lxRunOffline or WSL-DistroLauncher may store the linux filesystem into any location.

You may check many options to know the location of the WSL folder. For instance, I think the easiest option is to use lxRunOffline to know the installation folder.

## You can use lxrunoffline to check which WSL distributions have installed
## using:   lxrunoffline list

C:\> lxrunoffline list
backup
Ubuntu-18.04    

## And you can use it to get the location of any of these WSL installations
## using:   lxrunoffline get-dir -n <name of distribution>

C:\> lxrunoffline get-dir -n backup
c:\wsl\installed\backup

C:\> lxrunoffline get-dir -n Ubuntu
C:\Users\Jaime\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState

Once you know the location of the installation folder, the /home/<username> is under <installation folder>\rootfs\home\username.

  • For instance, if your installation folder is c:\wsl\ubuntu
  • the /home/<username> is in c:\wsl\ubuntu\rootfs\home\username

NOTE: Both Linux and Windows stores file permissions in different ways. Nowadays, the WSL DrvFS stores the Linux permissions as Streams (metadata) attached to the files you can see in Windows. Microsoft does not recommend to modify linux files using Windows programs. It is possible that some Windows applcations damage the linux permissions without notice it.

Tomas
  • 103
  • 4
Jaime
  • 2,169
  • 21
  • 20
31

With the current Windows 10 Insider (Fast ring: Windows 10 build 19025.1) you can mount your distro as a network drive.

WSL is accessible as wsl$, the path is your distribution name (wsl -l -q).

For example net use Z: \\wsl$\Debian /PERSISTENT:YES

J. Scott Elblein
  • 529
  • 1
  • 6
  • 20
foal
  • 561
  • 5
  • 8
  • Are you sure this is limited to WSL2? I thought as of 1903 you could explore the contents of the WSL file structure from within Windows. Creating a map network location would have been possible with that change. – Ramhound Nov 16 '19 at 15:38
  • As I wrote I am not sure about WSL2. There are two points: introducing WSL2 (from build 18432) and distribution backed by WSL 2. This feature appears along with WSL2 and I hope it works with any distribution. – foal Nov 16 '19 at 16:19
  • 1909 (WSL2) is 18363.476, not 18432(Insider Preview 20H1) unless you are saying, this is only on 20H1 builds? – Ramhound Nov 16 '19 at 21:19
  • Just to add: this is the preferred way of accesing those files as per https://devblogs.microsoft.com/commandline/do-not-change-linux-files-using-windows-apps-and-tools/ – mhl666 Dec 31 '19 at 15:31
  • Open windows explorer and type to open \\wsl$\ . Then choose your linux distribution to open folder or even map to a letter. Works with wsl version1. – arvati Apr 06 '20 at 11:26
14

It depends on which windows build you are on, for me in 2018 on Windows 10 Pro 64-bit, Version 1709 (OS Build 16299.522) and also Version 1803 (OS Build 17134.165) the location is still:

C:\Users\<username>\AppData\Local\lxss

The trick is when you're at C:\Users\<username>\AppData\Local you will not see an lxss folder (unless you happen to have unchecked "Hide protected operating system files (Recommended)" in your folder options).

However just append \lxss in the windows explorer address bar and it will take you to the folder.

(Note I did not have a %LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc or anything similar that was mentioned in Michael Bonds answer)

Update

Turns out there is legacy WSL which is what I had installed. Now WSL is provided via a Microsoft store app. There are versions for Ubuntu 18.04 LTS and also now a few other flavors of Linux (e.g. Debian). If you want to be up-to-date you should uninstall legacy WSL and install the Microsoft store version.

Where your home folder is will depend on which of these types of WSL you have installed. With the Microsoft store version it will, as mentioned in other answers, be located at:

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc \LocalState\rootfs

User
  • 3,597
  • 9
  • 37
  • 50
5
  1. Using WSL bash console, in your home directory, create a file with an arbitrary specific name such as "test_here.txt".
  2. Then using Windows Explorer, using the search box, search for the file test_here.txt.
  3. On the found file > right-click > Open file location.
Ellis
  • 169
  • 1
  • 2
  • I tried this. It doesn't work. I don't see the file in search. However, if I drop the file in /mnt/c/Users/ it obviously works. – Eamonn Kenny Jan 11 '19 at 16:39
  • I'm afraid I tried the WSL but I don't use this anymore. I didn't find it much useful. (I use cygwin daily, instead of WSL, and I find it very useful.) So I cannot verify it anymore, sorry ;) – Ellis Jan 13 '19 at 07:54
  • Searching for rootfs works. you can then navigate the unbuntu file system from there. – tigr Jan 21 '19 at 04:14
  • Believe it or not, this method did not work for me. Neither rootfs or the file I created in my WSL home directory can be found by Windows. I'm so very confused. – dx_over_dt Jul 27 '20 at 17:06
3

Four steps for windows 10 pro to pin your Debian/Ubuntu/OpenSUSE $HOME to the start menu of Windows:

  1. From start menu start File Explorer
  2. In address bar (not search bar) type %LOCALAPPDATA%.
  3. In search bar look for your $HOME directory name, in my case it was ekenny. There will be about 3 versions of this but you want the one with really long path.
  4. Right click your home directory and click "Pin to Start".

Now you have your home directory pinned to your start menu. I tried creating a shortcut but that doesn't go anywhere intelligible.

Eamonn Kenny
  • 171
  • 2
3

On my setup (WSL Ubuntu under the "Windows 10 development environment" downloaded from https://developer.microsoft.com/en-us/windows/downloads/virtual-machines) the AppData folder was hidden by default. So had to:

  • open windows explorer
  • go to C:\Users\User\
  • select view on the meny
  • check hidden items
  • then the AppData folder appears under C:\Users\User
  • and I found my /home/user under C:\Users\User\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_*\LocalState\rootfs\home\user (where * is probably a local code or version depending code of some sorts)

Don't know why it's tucked away like that.

Kjetil S.
  • 549
  • 4
  • 6
1

I just needed to find /etc/environment using Ubuntu 16.04 looking into Windows 10 NTFS storage. I found it here:

C:\Users\USER_NAME\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc\LocalState\rootfs\etc\environment
  • I changed /mnt/c/ to C:\ for Windows nomenclature.
  • I also changed all occurrences of / to \ for same reason.
  • You need to replace USER_NAME with your Windows User Name.
  • I had to use sudo -H Nautilus to get permissions to view the User Files stored in WSL.
  • NEVER update your Linux files in WSL using a Windows application. It will corrupt your Linux data.

From the Linux (Ubuntu 16.04) side the nomenclature would be:

$ sudo cat /mnt/c/Users/USER_NAME/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu16.04onWindows_79rhkp1fndgsc/LocalState/rootfs/etc/environment

PATH="/mnt/e/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
export LIBGL_ALWAYS_INDIRECT=Yes
export DISPLAY=localhost:0.0
0

If you installed your distribution with Chocolatey, the path to the home directory is:

C:\ProgramData\chocolatey\lib\wsl-<distribution-name>\tools\unzipped\rootfs\home

For example for Ubuntu 18.04:

C:\ProgramData\chocolatey\lib\wsl-ubuntu-1804\tools\unzipped\rootfs\home
Marco Lackovic
  • 1,309
  • 4
  • 17
  • 24