How to access Windows folders from Bash on Ubuntu on Windows

141

51

On the Bash on Ubuntu on Windows app, I only have

root@localhost:~# ls -a
    .bash_history  .bashrc  .profile

How do I access all of the Windows folders like Documents, Downloads, etc.?

Sergei Wallace

Posted 2016-04-16T17:33:13.120

Reputation: 2 239

Answers

225

You'll find the Windows C:\ structure at /mnt/c/ in the Bash environment.

Therefore, my Documents folder is at /mnt/c/Users/Ben/Documents/.

Ben N

Posted 2016-04-16T17:33:13.120

Reputation: 32 973

why does mnt not show up with ls -a? – Sergei Wallace – 2016-04-16T17:52:27.830

4You were in the ~ directory, your home in the Bash environment, which is not the root (/). If you had done cd / first, you would have seen mnt. – Ben N – 2016-04-16T18:01:49.550

When it comes to building scripts, the 2nd sentence doesn't necessarily follow from the first. Windows lets you move your documents folder around all over the place. It would be nice to be able to read that info from the Windows registry or similar while using bash. – Joel Coehoorn – 2016-10-06T23:46:25.323

1how can I access stuff outside C? for instance, I connected a phone via MTP and its files shows up at a path "This PC\PhoneName" – Michael – 2016-12-20T16:47:43.590

1

@Michael Unfortunately, MTP devices are very unlike normal file systems. They aren't even accessible from a normal command prompt, so I don't know of a way to access them from BoUoW.

– Ben N – 2016-12-20T17:05:41.140

Thanks Ben! Noticed a comment about using a WebDAV server on the device, and that seems to work! – Michael – 2016-12-20T17:10:00.237

Well I'm going to have to retract WebDAV as a valid solution... in transferring 1005 image files across WebDAV, 925 were corrupted (as verified by md5 on the original and copied file)! – Michael – 2016-12-24T18:19:42.367

so just make a link to drive in your home folder: ln -s /mnt/c/ . – Yar – 2017-02-23T01:21:54.687

I am getting No such file or directory error. – Iqbal – 2017-07-12T10:08:01.113

@Iqbal Note that Linux is case-sensitive, so make sure to type uppercase letters when necessary. If that doesn't help, could you cd into the directories one at a time and tell me which is the problem? – Ben N – 2017-07-12T14:00:10.873

24

Alternatively,

  1. Hold down Shift while right-clicking in your desired Windows directory
  2. Select "Open PowerShell window here"

PowerShell Context Menu

  1. Once you're in PowerShell, type bash

You'll be able to use any Bash commands directly to operate on the files and folders in that Windows directory. By using this method, you don't have to manually cd into your directories especially when you've a deep-rooted directory to access.


Update as of Windows 10 1809:

Above still works, but there's an easier method now.

  1. Hold down Shift while right-clicking in your desired Windows directory
  2. Select "Open Linux shell here"

Keith OYS

Posted 2016-04-16T17:33:13.120

Reputation: 351

1In my right-clicked context menu, I don't see the item for Open PowerShell window here – Yu Shen – 2018-04-24T01:47:14.960

1yep, same here..... – Maksim Kniazev – 2018-05-13T03:33:06.253

@YuShen Do ensure that you've the latest Windows 10 update installed. For instance, the current version is 1803 and it has the option. I realize some machines which weren't updated still has CMD as their default and hence does not have this option in the context menu. – Keith OYS – 2018-05-27T12:55:39.610

It doesn't work, the bash commands opens in default ubuntu user directory, not curret windows directory – mxdsp – 2018-10-22T16:44:42.410

@mxdsp What were your steps and your Windows version? Please detail it out for me so I could help you further. If you did it correctly, it would bring you into your current windows directory. Ain't wise downvoting just because it doesn't work for you. – Keith OYS – 2018-10-23T17:21:16.890

You can change the default from CMD to Powershell and back again by following these steps. Start > Settings > Personalization > Taskbar > Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X – Nathaniel – 2019-09-13T03:40:35.837