2

Relatively unexperienced user here.

Problem description: I am using a windows laptop to work (provided by my company) where I am using Widows subsystem for Linux. The reason I use Linux is because I have several scripts/tools that run on Linux only. I often need to move files from windows to linux and vice versa. Doing it from command line is a painful and long series of cd(s) and cd ..

Is there a recommended way to quickly access Windows folders from Linux and Linux from windows (e.g. powershell)? One of the main use cases is moving files from one system to the other.

now I do:

mv my_file new_path_to_my_file
  

The full path in windows is very long and error prone.

Thanks for the help!

3
  • Is this a Windows question (what software can make this easier?) or a Linux question (what commands can make this process simpler?)? 🤔
    – matigo
    May 26, 2021 at 14:28
  • can you not use a cloud based system such as Dropbox or GoogleDrive to move the file to as a stepping point?
    – graham
    May 26, 2021 at 14:39
  • @24601 No need for anything that drastic. WSL provides easy access to transfer files between Windows and Linux installations installed in WSL. The OP here just appears to be looking for a way to reduce the amount of typing (and thus errors) that result from long paths. May 26, 2021 at 20:48

2 Answers 2

6

Create a symlink within WSL/bash to the Windows path you want to simplify.

hbo@quark:~$ cd
hbo@quark:~$ pwd
/home/hbo
hbo@quark:~$ ln -s  /mnt/c/Users/Howard\ Owen winhome
hbo@quark:~$ sudo ls winhome
 ...
 Contacts                NetHood
 Cookies                 Pictures
 Desktop                 PrintHood
 Documents               Recent
 Downloads              'Saved Games'
 Favorites               Searches'
 IntelGraphicsProfiles  'Start Menu'
 Links                   Templates
'Local Settings'         Videos
 Music                   ntuser.dat.LOG1
'My Documents'           ntuser.dat.LOG2
 NTUSER.DAT              ntuser.ini
hbo@quark:~$
1
  • Thanks Howard Owen. This helped! I didn't know about symlinks.
    – Faber
    May 28, 2021 at 7:32
1

Access to Windows Files from WSL/Linux

As with Howard Owen's answer, I use a symlink (also called "winhome") to my Windows profile directory. But I'm not sure that answers your real question, since it doesn't sound like the Windows directory you need to access is your profile (based on the "long and error prone" part). That said, you can always create a symlink to whatever Windows directory you need.

Or you can create a bind mount. E.g.

sudo mkdir /mnt/project
sudo mount --bind /mnt/c/really/long/path/to/project /mnt/project
ls /mnt/project

That said, there's one very important consideration when accessing Windows files from Linux -- WSL1 is around 10 times faster than WSL2 in doing so. You don't mention which version you are using, but I'd recommend making sure you at least have a WSL1 instance installed for these types of file operations, especially if the workload involves a large number of small files.

Accessing files on the Linux/WSL filesystem from Windows

You mention PowerShell specifically. To create a shortcut from the Windows drive in PowerShell to a directory in WSL/Ubuntu, do the following from an administrative PowerShell session:

Set-Location location\for\link
New-Item -Path project -ItemType SymbolicLink -Value \\wsl$\Ubuntu

... where project is the name of the shortcut directory you want, and \\wsl$\Ubuntu is dependent on your distribution name (obtained by wsl -l, but "Ubuntu" by default for the first Ubuntu distribution installed).

Of course, you can just as easily use a file manager (e.g. File Explorer, although I prefer Directory Opus) in Windows if you'd like. The \\wsl$\Ubuntu pseudo-share is available whenever WSL is running (but disappears when the WSL instance is in the "Stopped" state).

Using the symlink creates an interesting case, at least for me. While I would have expected access to fail if WSL isn't running, but it seems that just listing the contents of the location\for\link\project will result in the WSL instance going form "Stopped" to "Running". So that seems good.

Other options

You may also want to look into "quick cd" options, as mentioned in this blog post. These are available for both PowerShell and certainly most any Linux distribution. The one mentioned by Hanselman apparently works for both.

You must log in to answer this question.

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