How can I export files from Ubuntu WSL to windows or any other directory so that I can use/edit that file in windows
-
Which files do you need to edit and why can't they be edited by a Linux program? – WinEunuuchs2Unix May 20 '18 at 15:56
-
1IMO it is a good question and people new to Linux using WSL are obviously going to be more comfortable and/or expect to manage files / edits with windows tools. At least point them to Linux tools such as nano ;) – Panther May 20 '18 at 16:29
-
Voted to leave open and upvoted existing answer! @Panther – Fabby May 20 '18 at 17:11
-
Close Voters The duplicate candidate spells out how to find out where files are located. OP is not asking where files are located. OP is asking how to edit them using Windows (not possible, but is possible with a Linux GUI app). – WinEunuuchs2Unix May 20 '18 at 17:23
4 Answers
The short answer is right now you can not, but there are some solutions.
First the warnings:
I have to provide this guidance at least 2-3 times a day so instead I am publishing it here so everyone can find / link-to this guidance.
There is one hard-and-fast rule when it comes to Bash on Windows:
DO NOT, under ANY circumstances, create and/or modify Linux files using Windows apps, tools, scripts, consoles, etc. Also note: Opening files using some Windows tools may read-lock the opened files and/or folders, preventing updates to file contents and/or metadata, essentially resulting in corrupted files/folders.
Creating/changing Linux files from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro! Note: Your "Linux files" are any of the files and folders under %localappdata%\lxss - which is where the Linux filesystem - distro and your own files - are stored on your drive
But this means any files in %localappdata%\lxss
Read the link for full details and additional information as to why. To the best of my knowledge this is currently marked as "might fix" (upgraded from "wont fix").
There are a few options:
First:
So what SHOULD I do?
To work on files using both Windows and Linux tools, store & work on those files in your Windows filesystem, and access them from both Windows and from Bash via /mnt//path (e.g. /mnt/c/dev/project/...)
There are "work arounds" listed here :
https://github.com/Microsoft/WSL/issues/1524
But no guarantee you will not break things if you try those.
Second, make a shared directory in windows and mount it in WSL:
You can also try https://github.com/Microsoft/WSL/issues/1319
Make a folder in Windows, call it
%userprofile%\projects
In Windows subsystem for linux, do the following:
ln -s /mnt/c/Users/[YourWindowsUserName]/projects ~/projects
Any Linux-related file that you want to edit, edit it in ~/projects, and you will be 100% fine.
Third (possibly best for some) is to use the linux tools.
nano
is an easy to use command line editor
nano file_to_edit
The key combinations to save / exit are at the bottom of the editor
Here is a basic nano guide: https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/

- 102,067
Just open a bash terminal at the appropriate path:
$ explorer.exe .
Et Voilà!

- 3,154

- 111
The easiest way of editing Linux files stored in WSL (Windows Subsystem for Linux) is to use Linux GUI applications. After the initial setup of Ubuntu for Windows 10 is complete you need to install vcxsrv
and Ubuntu desktop. This will give you full access to GUI apps such as gedit
and run scripts that contain GUI dialogs such as zenity
or yad
.
See this answer: What's the easiest way to run GUI apps on WSL as of 2018?
If you use a Windows app to modify a Linux file stored in a WSL directory you will corrupt the data:

- 102,282
The files are already available in windows. When you don't want to remember the difficult path, open a wsl console, go to the relevant directory and enter explorer.exe .
. This will open a windows explorer in the current directory.
Alternative:
When you use the command df
, you will see something like
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 240047100 56379724 183667376 24% /
none 240047100 56379724 183667376 24% /dev
none 240047100 56379724 183667376 24% /run
none 240047100 56379724 183667376 24% /run/lock
none 240047100 56379724 183667376 24% /run/shm
none 240047100 56379724 183667376 24% /run/user
cgroup 240047100 56379724 183667376 24% /sys/fs/cgroup
C:\ 240047100 56379724 183667376 24% /mnt/c
H:\ 987142140 455640896 531501244 47% /mnt/h
In this case the C:\
and H:\
partitions are mounted under /mnt
and you can copy the files to these drives
mkdir -p /mnt/h/folder_I_own_in_Windows/ubuntu_files
cp * /mnt/h/folder_I_own_in_Windows/ubuntu_files

- 141
- 3