How to change directory within Ubuntu WSL in Windows format?

Viewed 15311

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\"
>
3 Answers

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.

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

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.

Related