To open files with their default Windows applications from within the Windows Subsystem for Linux (WSL), use the cmd.exe /c start command followed by the absolute path to the file. Because WSL uses a Linux-style file system, you must first convert your current directory or specific file path to the corresponding Windows drive letter format using wslpath. This method leverages the Windows host's registered file associations, ensuring that documents, images, and code files launch in their native editors without requiring manual configuration inside the Linux environment.
Understanding File Path Translation
The core challenge when interacting with Windows resources from WSL is the difference in path syntax. Linux uses forward slashes (/) and root directories like /home/user, while Windows uses drive letters (e.g., C:) and backslashes (\). The cmd.exe utility running on the Windows host does not understand Linux paths directly. Therefore, any attempt to open a file via Windows commands requires translating the location into a format Windows recognizes.
WSL provides a built-in utility called wslpath specifically for this purpose. This tool converts Unix-style paths into Windows-style paths or vice versa. When opening a file, you typically need to convert a Linux path to a Windows path. For example, if you are in the /mnt/c/Users/YourName/Documents directory, wslpath can translate this to C:\Users\YourName\Documents. This translation is the critical bridge that allows seamless integration between the two operating systems.
Basic Command Structure
The standard approach involves chaining thecmd.exe execution with the /c start flag. The /c parameter tells the command processor to carry out the command specified by the following string and then terminate. The start command is the Windows equivalent of "open with default application." It queries the Windows registry for the file association and launches the appropriate program.
Here is the general structure:
cmd.exe /c start "" <translated_path>
Note the empty quotes after start. In Windows command line syntax, if the first argument to start contains spaces, it might be interpreted as a window title rather than the file path. Providing an empty string "" explicitly sets the window title to nothing, ensuring the next argument is correctly parsed as the file path. Without this, complex filenames often fail to open.
To execute this from your terminal, you combine the conversion and the start command:
cmd.exe /c start "" $(wslpath 'C:/path/to/file.txt')
If you are working with a relative path in your current WSL directory, you can use the variable $PWD which represents the present working directory. You would pass this through wslpath to get the full Windows absolute path.
cmd.exe /c start "" $(wslpath "$PWD/filename.ext")
This one-liner is efficient and works for most common file types including PDFs, Word documents, images, and source code files. It relies entirely on the settings configured in your Windows OS, meaning if you have changed the default app for .jpg files in Windows Explorer, WSL will respect that change automatically.
Handling Spaces in Filenames
A common pitfall occurs when file names contain spaces. Even with the empty quotes trick, it is safer to ensure the path is properly quoted during the translation process. You can wrap the output ofwslpath in double quotes within the shell command.
cmd.exe /c start "" "$(wslpath "$PWD/my file.docx")"
This ensures that the Windows start command receives a single, unbroken string representing the file location, preventing errors where Windows tries to open my instead of my file.docx.
Opening Directories and Explorers
Sometimes you do not want to open a specific file but rather browse a folder. You can achieve this by pointing thestart command at a directory path. When you provide a directory path to cmd.exe /c start, Windows opens the File Explorer window at that location.
cmd.exe /c start "" $(wslpath "$PWD")
This is particularly useful when you are deep in a project structure in WSL and need to see the files in the Windows GUI context. It effectively mirrors the behavior of right-clicking a folder and selecting "Open in Explorer." If you want to open a specific subdirectory, simply append the folder name to the path before translation.
For more advanced navigation, you might prefer to launch the Windows Terminal or a specific explorer instance. However, for simple browsing, the start command is sufficient. It maintains consistency with how files are opened, treating folders as navigable entities within the default file manager.
Creating Convenient Aliases
Typing the fullcmd.exe /c start ... sequence repeatedly can be tedious. To streamline your workflow, you can create aliases in your WSL shell configuration file, typically ~/.bashrc or ~/.zshrc. By defining a short function or alias, you can open files with a single keyword.
Add the following to your configuration file:
alias wo='cmd.exe /c start "" $(wslpath "$PWD/$1")'
After reloading your shell with source ~/.bashrc, you can use wo filename.pdf to open that file. This alias takes the first argument provided to it, combines it with the current working directory, translates it, and launches it. This significantly reduces friction when switching between coding in the terminal and reviewing outputs in Windows applications.
If you frequently work across different drives, you may also want an alias that handles absolute paths directly without needing $PWD. A more robust function could check if the argument starts with a slash or drive letter. However, for daily development tasks, the basic alias covers 90% of use cases.
Troubleshooting Common Issues
While this method is generally reliable, several issues can arise depending on your WSL version and Windows configuration. One frequent error is "The system cannot find the file specified." This usually happens when the path translation fails because the file does not exist in the mounted Linux filesystem, or the path contains characters thatwslpath cannot handle. Always verify the file exists in WSL before attempting to open it using ls.
Another issue is that the file opens but in a blank window. This often indicates that the default application associated with the file type in Windows is misconfigured. Check your Windows Settings > Apps > Default Apps to ensure the correct program is assigned to the file extension. Additionally, some older versions of WSL had bugs with wslpath returning incorrect paths for symlinks. Ensuring you are running the latest version of WSL via wsl --update in PowerShell can resolve these edge cases.
If you encounter permission errors, remember that WSL runs as a user mapped to your Windows account. Generally, permissions are inherited, but if you are trying to open a file owned by root or another user, you may need to adjust permissions in Windows Explorer or use sudo in WSL if necessary. For most personal files, this is not a concern.
For users managing large datasets or external drives, understanding how WSL mounts these volumes is helpful. As discussed in related guides about transferring installations or mounting folders, the way drives are attached affects path availability. If a drive is not mounted correctly, wslpath will fail because the Linux path does not exist. Ensure your Windows drives are accessible via /mnt/ before attempting to open files from them.
Finally, consider security implications. Opening files from WSL executes commands on the Windows host. While start is safe, be cautious with arbitrary strings passed to cmd.exe. Never pass user input directly into a cmd.exe command without validation, as this could lead to command injection vulnerabilities. Stick to using wslpath on known file paths to maintain a secure boundary between the two environments.
Frequently Asked Questions
Can I open a file directly without converting the path?
No, Windows commands likestart do not understand Linux paths such as /home/user. You must use wslpath to translate the path to a Windows format like C:\Users\user before passing it to the command. Attempting to use a Linux path directly will result in a "file not found" error.
Why does my file open in a new window instead of the existing application?
Thestart command typically launches a new instance of the application unless the application supports Single Instance Mode. Most modern editors like VS Code or browsers support this, so they will switch to the existing window. Older applications may always open a new window regardless of the command used.
How do I open a file in a specific editor instead of the default one?
You can bypass the default association by specifying the executable directly. For example, usecode $(wslpath "$PWD/file.txt") to open a file in Visual Studio Code. This requires the editor to be installed and accessible in your Windows PATH. This method gives you explicit control over which application handles the file.
Does this work for network drives or UNC paths?
Yes,wslpath can handle UNC paths if they are properly mounted in WSL. If you have a network share mounted at /mnt/share, you can convert it to \\server\share and open it. However, performance may vary depending on the network latency and the stability of the mount point.
What should I do if wslpath returns an empty string?
An empty string usually means the input path is invalid or the file does not exist in the WSL filesystem. Check your current directory withpwd and verify the file name. Also, ensure you are using the correct syntax for wslpath, especially regarding quotes around paths containing spaces.