Among its numerous advantages, one notable feature is the seamless accessibility of Linux files stored within WSL from the Windows operating system itself.
In this article, you'll explore various methods of accessing WSL files. This will enable smooth file management and interoperability between Windows and Linux environments.
You will look at both graphical and command-line ways of accessing WSL files inside Windows.
Access WSL files using Windows Explorer
The most basic way of accessing a file on Windows is by launching the Windows File Explorer. The file manager is present on the taskbar, and you can just open it to browse files. Wait! That is for Windows files, but for Linux?
Yes. WSL indeed stores the file inside Windows because it is the host. If you have set up the WSL correctly on Windows, you will see a Penguin icon on your File Explorer.
Just click on it.
You will see the name of the WSL distributions you have installed currently as folders. I have two; an Ubuntu and an OpenSUSE Tumbleweeed.
Double-click on the one you need to access. Now, you are inside the root directory of that system.
Go inside the home → username folder, and there it is.
You are now accessing the home directory of the default user. Double-click on any file to open it on a Windows app. You can see in the screenshot below, I have opened the .bashrc
file on Notepad app.
Use the address bar of Explorer
You can use the address bar of Windows Explorer to go into the WSL folders. For this, click on the to address bar. When it is changed to editing, enter:
\\wsl$
This will bring you to the same folder, where all the WSL distributions are listed as folders. Click on any to enter into it.
💡 Tip: Open the current Linux directory location in Windows
Imagine that you are using Linux through the Windows terminal and you are in a specific directory location. Now, you think it would be better if you could access it in the file explorer.
This is possible and quite easy. Enter the following command on the WSL terminal.
explorer.exe .
Here, the .
refers to the current directory you are in. This means that your current directory will be opened in the Windows file explorer.
Similarly, while inside the WSL, you can specify a directory path to open that folder in Windows Explorer.
As you can see, the mentioned directory is opened in Windows Explorer and you can access the files.
Open a WSL text file in Notepad
While there are terminal-based text editors available in Linux, you may not be comfortable with the idea of editing files in the command line.
Thankfully, you can easily open those Linux text files using Windows's Notepad.
notepad.exe /path/to/the/file/inside/wsl/distribution
Accessing files between WSL and Windows
As you can easily guess by now, it is possible to access files between WSL and the Windows host operating system.
Here are a few tips on accessing files between Windows and Linux inside WSL.
Edit Windows files inside WSL
While inside WSL, you can open a file stored on the Windows filesystem using Linux tools like the Nano editor.
For this, we use the Mounted Drive concept.
nano /mnt/c/Users/username/Documents/filename
Here, the /mnt/c
represents the C drive mounted to the WSL. So, what the command actually does is, open the specified file on the location specified in nano editor.
You can use /mnt/d
, if you have a drive located with D:
in Windows.
Copy files between WSL and Windows
Inside the WSL, you can copy a file from WSL to a specified Windows folder. To do that, use the cp
command:
cp /home/$USER/filename /mnt/d/Documents/
This will copy the file called filename
from the home directory of the user to the Documents folder (if exists) on the D drive.
Similarly, if you want to transfer a file from a Windows folder into the WSL system, use:
cp /mnt/d/Documents/filename /home/$USER/
That's it. You have copied the files.
Wrapping Up
Here, you learned about accessing files between Windows and Linux running inside WSL. The ability to access Linux files easily from Windows is super helpful for Windows users. Let me know if you have any questions.
from It's FOSS https://ift.tt/16iANmX
via IFTTT
Tidak ada komentar:
Posting Komentar