8

I have installed Cygwin on Windows. To change dir in Cygwin could be done in 2 ways:

In Unix format:

cd /cygdrive/path/to/folder/

In Windows format (surrounded by double quotes):

cd "C:\Path\To\Folder\"

Is there a way to change dir in Ubuntu WSL like can be done on Cygwin, using Windows format?

I get this error when trying on Ubuntu:

$ cd "C:\Path\To\Folder"
-bash: cd: C:\Path\To\Folder\: No such file or directory
$ cd "C:\Path\To\Folder\"
>
Ger Cas
  • 2,188
  • 2
  • 18
  • 45

4 Answers4

13

No. In order to access Windows files from WSL you need to visualize an Ubuntu VM that has mounted NTFS drives, so access needs to be using /mnt/c/... or /mnt/d/... etc.

You need to use forward slashes as shown, since backward slashes (\) will be interpreted as escape characters within WSL.

Cahit
  • 2,484
  • 19
  • 23
7

WSL stores your Windows drives in the /mnt folder, with the name of the drive as a subfolder. For example your C:\ drive will be present at /mnt/c/ for you to use.

Keeping this in mind, you can swap to your specific folder like so:

cd /mnt/d cd /mnt/e/username/folder1/folder2

Oscar Rangel
  • 848
  • 1
  • 10
  • 18
3

copied from sincostan, define this function in your .bashrc:

cdw() { local d=`wslpath "$1"`; cd "$d"; }

then , use like this:

cdw 'E:\username\folder1\folder2'

it seems there is no way to avoid inputing the quote marks.

Max
  • 95
  • 6
2

One more alternative, without defining the function, e.g. for temporary use:

cd `wslpath 'E:\example\path'`

Note that you need both backtick surrounding the wslpath command and its parameter, and single quotes surrounding the windows path, to avoid unintentional escaping of backslashes.

panuv
  • 31
  • 2