Access windows files from wsl

Cover image for Access the Windows file system through WSL!

Have you ever wondered, how to access the windows file system through WSL? If the answer is yes you are in the right place!

Microsoft WSL has given us an incredible way to access the windows file system, you have just to navigate through an exact path to do it. Without further due, let’s dive into the topic.

1. Use the cd command in the Linux terminal.

To access the windows files you have to navigate through /mnt/your_windows_path

cd /mnt/c/Users
**OR**
cd /mnt/d/your_folder/your_folder

Enter fullscreen mode

Exit fullscreen mode

Now you have access to every file in the Linux and Windows file systems.

2. Moving files between the two systems through WSL.

If you want to move files between the two operating systems you can simply use the cp or mv commands.
cp — command for copying files
mv — command for moving files
Use of cp command

cp /mnt/c/file.txt /home/username/Documents

Enter fullscreen mode

Exit fullscreen mode

Use of mv command

mv  /mnt/c/file.txt /home/username/Documents

Enter fullscreen mode

Exit fullscreen mode

3. Editing windows files through WSL.

To edit windows files through the Linux terminal using WSL, you have to use any text editor that can be opened in the terminal. One of the most famous text editors is nano. In our example, I am going to use the nano editor.
Type into the terminal nano and the path to the file.

sudo nano /mnt/c/Users/file.txt

Enter fullscreen mode

Exit fullscreen mode

Now you can edit freely files from your terminal.

4. Creating files in windows through WSL.

To create a file in a specific windows directory you have first to navigate to it and then use the touch command to create a file.
touch — a command that creates a file.
!!! The file extension can be anything you want.

cd /mnt/c/Users/Public/Documents/ 
touch filename.txt

Enter fullscreen mode

Exit fullscreen mode

The file is created and can be opened from both systems.

5. Deleting files from the windows file system through WSL.

To delete windows files using WSL, you have to navigate to the directory where the file lives and use the rm command.
rm — a command that deletes files / directories

cd /mnt/c/Users/Public
sudo rm example_file.jpg

Enter fullscreen mode

Exit fullscreen mode

Congratulations you learned 5 vital skills about working with the Linux terminal. 🎺🎺🎺
If you have any questions, comment down, I will answer as soon as possible.

I’m starting to learn how to use the terminal with Ubuntu on WSL (Windows).

Just from the very beginning of the course it says that if you use the ls command it should show you your «home» directories, but mine is something like this:

(base) paloma@DESKTOP-ISCC0ON:~$ ls
Anaconda3-2021.11-Linux-x86_64.sh  anaconda3

(base) paloma@DESKTOP-ISCC0ON:~$

And if I try to change directory something like this happens:

(base) paloma@DESKTOP-ISCC0ON:~$ ls
Anaconda3-2021.11-Linux-x86_64.sh  anaconda3

(base) paloma@DESKTOP-ISCC0ON:~$ cd Documents
-bash: cd: Documents: No such file or directory

(base) paloma@DESKTOP-ISCC0ON:~$

Can somebody tell me why is this happening and what can I do, please? I’m a complete newbie.

NotTheDr01ds's user avatar

NotTheDr01ds

15.8k6 gold badges52 silver badges80 bronze badges

asked Nov 23, 2022 at 11:47

Paloma's user avatar

Everything in @Tooster’s answer is corrected, but let me address your main question a bit more directly:

(base) paloma@DESKTOP-ISCC0ON:~$ cd Documents
-bash: cd: Documents: No such file or directory

Can somebody tell me why is this happening and what can I do, please?

You appear to be wondering why this isn’t taking you to the Documents folder in your Windows home directory.

It’s important to understand that the home directory in Ubuntu/WSL is not the same as your Windows home directory, nor should it be. Your Ubuntu home directory is in a virtual SSD provided by WSL. This virtual SSD provides the Linux compatible filesystem that Ubuntu needs, whereas your Windows drive is formatted as NTFS and won’t have 100% compatibility.

WSL does provide a way to get to the Windows files (including your home directory), as mentioned by @Tooster.

From inside Ubuntu:

cd /mnt/c/Users/<your_Windows_username>
ls

That should show you all the files and directories in your Windows profile (a.k.a. home) folder.

Also perhaps reading as additional background — My answer to Where is WSL located on my computer?.

answered Nov 28, 2022 at 2:29

NotTheDr01ds's user avatar

NotTheDr01dsNotTheDr01ds

15.8k6 gold badges52 silver badges80 bronze badges

First of all try to format code and output from terminals using the fenced code block format.

And now to the meritum.

  • current working directory is the directory you are in. Your home directory (often denoted with ~) is usually located in the /home/<username>/
  • ls — command listing files in the current directory
  • ls [arguments...] — this command lists the files inside directories provided as arguments
  • cd [argument] — change directory command. using it without argument takes you to your home directory
  • / is root directory in linux and an absolute paths start with it
  • . is a current directory and if path starts with ./something or without it something, then current directory is assumed (path is relative to current location)
  • .. is parent directory.

Based on the (base) in thee prompt and on the names of the files above, I’m gonna say that you are using conda environment on your WSL (Windows subsystem for linux). Why are you using it is not my business, but you seem to have skipped a few steps when learning linux and WSL first. Try starting with https://linuxjourney.com/ (especially command line section and filesystem section). Then learn about differences in linux and windows structure.


@EDIT because I only noticed you are using Linux on Windows

Because linux’ and windows’ filesystems are a bit different, when you start linux on windows a virtual filesystem is created for you. To access your windows files from linux you would have to access /mnt/<drive>/<...windows files> (note the / at the beginning — that’s an absolute path)

Linux is structured as a single tree rooted at / and external filesystems are usually mounted at /mnt (read hier(7) for more info). Windows’ filesystem is composed of «drives» — single trees rooted at C:/, D:/ etc., so it’s only natural for both of those systems to have different mechanism for accessing each other’s files.

Read more at https://ling123labs.com/posts/WSL-files-in-Windows-and-vice-versa/

answered Nov 23, 2022 at 12:21

Tooster's user avatar

ToosterTooster

4372 silver badges13 bronze badges

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Table of Contents

Solidstudio needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Privacy Policy.

share article with

Introduction

No matter if you program in Java or Kotlin or with other technologies, operating on Linux has a number of advantages. One of them is access to Linux Bash with its useful commands.

However, some developers have to or prefer working on Windows. As stackoverflow.com 2020 survey showed, almost half of developers (45,8%) work in the Windows environment. There are tools that bring them closer to the Linux world like Cygwin.

The WSL provides a near-native Linux experience

Some time ago Microsoft introduced WSL, a new tool that brings Windows users even closer to the Linux experience. Here you can find gathered some frequently asked questions and our expert’s experience to help you get a better understanding of the WSL.

What is WSL?

WSL or Windows Subsystem for Linux is a part of the Windows operating system that allows running native Linux binaries. A number of distributions exist that can be installed and used.

How can I install WSL?

The first thing to do before installing any Linux distribution is to install the WSL itself.

Go to Control PanelProgramsPrograms and FeaturesTurn Windows features on and off.

Select Windows Subsystem for Windows, confirm, and restart the system.

windows install

Now you are ready to select and install a Linux distribution of your choice.

What Linux distributions are available on WSL?

To find a list of available distributions open Windows Store and search for «Linux».
The most popular are:

  • Ubuntu 18.04 and 20.04
  • SUSE Linux Enterprise Server
  • Debian
  • Fedora Remix for WSL
  • Kali Linux

windows-store-search

Is it possible to run graphical Linux applications from WSL?

Yes, it is possible. You need to install an X Window System server application on your Windows, for example Xming X Server for Windows.

Then check if your WSL system has a DISPLAY environment variable set up. If not set it to :0.

export DISPLAY=:0

After this configuration you are free to run native Linux applications with user interface.

xclock

Where is wsl.conf located?

Each WSL instance can be further configured by creating and editing a config file /etc/wsl.conf.

How to access Windows files from WSL?

All fixed drives with the NTFS or ReFS file system are automatically mounted in /mnt directory. For example a

C: drive can be accessed in /mnt/c/

The directory where drives are mounted can be specified in /etc/wsl.conf as follows:

[automount]
root=/

This setting will cause drives to be mounted under the root folder, so the C: drive would be accessible through /c folder.

How to access pendrive from WSL?

Unlike fixed drives, removable drives are not mounted automatically. To access files stored on a USB stick you need to mount it yourself. For this purpose, use these commands (assume the drive letter in Windows is F):

sudo mkdir /mnt/f
sudo mount -t drvfs H: /mnt/f

How to connect to a DVD drive from WSL?

Optical drives are not as popular nowadays as they used to be. Nonetheless, they can be accessed the same way as pendrives (assume G is the drive letter):

sudo mkdir /mnt/g
sudo mount -t drvfs G: /mnt/g

Where are WSL files stored?

WSL files are exposed through a network share \\wsl$\[distro name], for example my home directory is at \\wsl$\Ubuntu-20.04\home\pawelb.

Physically the WSL files are located at

%USERPROFILE%\AppData\Local\Packages\[distro name]

My home folder is at this rather long path

C:\Users\pawelb\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\pawelb.

However, it is worth noting that manipulating WSL files from within Windows should be avoided as it can destroy Linux-specific file metadata. If you need to manipulate files on both WSL and Windows, store them on a Windows drive and access them from within WSL via /mnt.

Is it possible to run Windows programs from within WSL?

Yes, the WSL was built with interoperability in mind. It can run native Windows programs. However, if this feature is not needed, the user can disable it by adding enabled=false into [interop] section in wsl.conf.

[interop]
enabled=false

What terminal application to use?

Any terminal can do the job, even the good old cmd.exe. Just run the WSL command in. There is however one great application that makes running the WSL console easier. It’s Windows Terminal and it can be installed from Windows Store. It automatically detects any WSL distributions installed and adds an option to run its console. It also supports regular Windows Command Line, PowerShell, and Azure console out of the box. Also, it supports tabs and split view inside a tab.

 wsl windows-terminal

Caveats of interoperability with Windows

By default, WSL can run Windows binaries and also appends its %PATH% variable into the $PATH variable of Linux running under WSL. In most cases, this is useful or at least does no harm. However, sometimes unexpected behavior occurs.

This happened when I tried to run npm.

$ npm -v
module.js:471
    throw err;
    ^

Error: Cannot find module '\\wsl$\Ubuntu-20.04\c\Programs\nvm\v6.10.2\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3

This error message is not helpful at all. What happened?

After some investigation, I found out that I had also installed npm on Windows and WSL was using this executable to run. This unfortunately failed under WSL environment.

A fix was rather simple. I disabled appending Windows %PATH% to WSL $PATH.

This can be done in two ways.

The first is to use the Registry Editor (regedit) to add a DWORD AppendNtPath with value 0 under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss. This affects all WSL distributions.

The second way is to set a property in /etc/wsl.conf. This affects only a single distribution.

[interop]
appendWindowsPath=false

The WSL is a great subsystem for Windows

With the introduction of Windows 10, a lot has changed. It seems that the system and its features are more and more thought-out and intuitive. A programmer needs a proper working environment. With WSL, Windows is keeping up with developments in this area, and looks like it is a step in the right direction. It’s worth having an eye on the development of this solution, hoping that in the future the developers will have a variety of systems that can really compete with each other. Looking for a good and stable, seamless tool, it is worth trying with the WSL.

Solidstudio develops a fleet of software products designed to facilitate EV charging network management. See more about our CPO platform and eMSP app.

Accessing local Windows files from a WSL distro can be achieved by navigating to the /mnt/c/ directory in your WSL Linux machine, or you can enter WSL from any Windows directory within a terminal.

This post is to demo both methods described for accessing Windows files from WSL:
# Navigate with cd /mnt/c/
# Open WSL from PowerShell Terminal

You can also create a symbolic link to create a new linked folder between your Windows computer and WSL. Check out my other blog post Create a Link Between Local Windows Files and WSL for more information.

Navigate in Terminal to /mnt/c/

When working within a WSL Linux environment, we can look at the files on our local Windows machine by navigating to the /mnt/ directory as shown in the example below.

# navigate to home (wsl) linux folder
cd ~

# navigate c:\temp folder on local windows computer
cd /mnt/c/temp

WSL access Windows Files

In the Windows Terminal above we are checking the contents of /mnt/ which is the local C & D volumes, and a folder named WSL.

Open WSL from PowerShell Terminal

When working within a PowerShell Terminal, we can open WSL from any Windows directory and the default Linux distribution will be opened with that local Windows-mounted path.

In the example below we’re creating a new folder on Windows within a PowerShell Terminal, navigating into the new folder and then entering WSL.

PowerShell Terminal Open WSL

The PowerShell colours are difficult to see on that path, but it shows the new folder we created within Ubuntu WSL.

Ubuntu 10

In this article, we will delve into the details of how to move files seamlessly between Windows and the Windows Subsystem for Linux (WSL). This guide will be particularly useful if you’re working in a mixed environment where you frequently need to transfer files between the two systems.

To easily move files between Windows and WSL, you can use symbolic links (symlinks) or bind mounts to access Windows files from WSL, and PowerShell to access WSL files from Windows. These methods allow for seamless file transfer between the two systems.

  1. Understanding the Windows Subsystem for Linux (WSL)
  2. Accessing Windows Files from WSL
    • Using Symlinks
    • Using Bind Mounts
  3. Accessing WSL Files from Windows
    • Using PowerShell
  4. Performance Considerations
  5. Conclusion

Understanding the Windows Subsystem for Linux (WSL)

Before we dive into the specifics, it’s important to understand what WSL is. WSL is a compatibility layer developed by Microsoft that allows you to run Linux binary executables natively on Windows 10 and Windows Server 2019. This means you can run a full-fledged Linux environment on your Windows machine without needing a dual-boot setup or a virtual machine.

Accessing Windows Files from WSL

Using Symlinks

One of the simplest ways to access Windows files from WSL is by creating a symbolic link (symlink) within your WSL environment to the Windows path you want to access. A symlink is essentially a pointer to another file or directory. Here’s how you can create a symlink:

ln -s /mnt/c/Users/YourUsername/ /home/YourUsername/winhome

In this command, ln -s is used to create a symbolic link. /mnt/c/Users/YourUsername/ is the Windows path you want to link, and /home/YourUsername/winhome is the location in your WSL environment where you want to create the symlink.

Using Bind Mounts

An alternative to symlinks is using bind mounts. A bind mount allows you to mount a Windows directory to a specific location in the WSL filesystem. Here’s an example of how to create a bind mount:

sudo mount --bind /mnt/c/Users/YourUsername/Project /home/YourUsername/project

In this command, sudo mount --bind is used to create a bind mount. /mnt/c/Users/YourUsername/Project is the Windows directory you want to mount, and /home/YourUsername/project is the location in your WSL environment where you want to mount the directory.

Accessing WSL Files from Windows

Using PowerShell

To access files on the WSL filesystem from Windows, you can use PowerShell. Here’s how you can create a shortcut from a Windows drive to a directory in WSL:

New-Item -ItemType SymbolicLink -Path "C:\WSL" -Target "\\wsl$\Ubuntu\home\YourUsername"

In this command, New-Item is used to create a new item, -ItemType SymbolicLink specifies that the item is a symbolic link, -Path "C:\WSL" is the location in Windows where you want to create the shortcut, and -Target "\\wsl$\Ubuntu\home\YourUsername" is the WSL directory you want to link.

Performance Considerations

It’s worth noting that WSL1 generally offers faster performance than WSL2 when it comes to accessing Windows files from WSL. If you’re working with a large number of small files, you might want to consider using WSL1 for better performance.

Conclusion

Moving files between Windows and WSL doesn’t have to be a complex task. By using symlinks, bind mounts, or PowerShell, you can easily navigate and transfer files between the two systems. Remember to consider the performance implications of your chosen method, especially when working with a large number of files.

Yes, you can access Windows files from within the WSL environment using symbolic links or bind mounts.

A symbolic link, or symlink, is a pointer to another file or directory. It allows you to access files or directories in Windows from within the WSL environment.

To create a symlink in WSL, you can use the ln -s command followed by the Windows path you want to link and the location in your WSL environment where you want to create the symlink. For example: ln -s /mnt/c/Users/YourUsername/ /home/YourUsername/winhome.

A bind mount allows you to mount a Windows directory to a specific location in the WSL filesystem. It provides a way to access Windows files from within the WSL environment.

To create a bind mount in WSL, you can use the sudo mount --bind command followed by the Windows directory you want to mount and the location in your WSL environment where you want to mount the directory. For example: sudo mount --bind /mnt/c/Users/YourUsername/Project /home/YourUsername/project.

Yes, you can access files on the WSL filesystem from Windows. You can use PowerShell to create shortcuts from a Windows drive to a directory in WSL.

To create a shortcut from a Windows drive to a directory in WSL using PowerShell, you can use the New-Item command with the -ItemType SymbolicLink parameter. Specify the location in Windows where you want to create the shortcut and the WSL directory you want to link. For example: New-Item -ItemType SymbolicLink -Path "C:\WSL" -Target "\\wsl$\Ubuntu\home\YourUsername".

Generally, WSL1 offers faster performance when accessing Windows files from WSL. If you’re working with a large number of small files, you might want to consider using WSL1 for better performance.

No, moving files between Windows and WSL can be done easily using symlinks, bind mounts, or PowerShell. These methods allow you to navigate and transfer files between the two systems seamlessly.

When choosing a method to access Windows files from WSL, consider the performance implications, especially when working with a large number of files. WSL1 generally offers better performance in this scenario.

  • Acdsee для windows 7 x64
  • Ac4 usb to rs 485 converter драйвер windows 10
  • Access to windows registry key finereader
  • Ac3 кодек скачать для windows 10
  • Ace player for windows 10