Skip to content

Instantly share code, notes, and snippets.

Last active Sep 26, 2020
What would you like to do?
macOS open command for WSL (Windows Subsystem for Linux)
# open
# macOS open command for WSL (Windows Subsystem for Linux)
# written by benjamin gwynn (
# get latest version here:
# You can run this on WSL wuth no prior setup or changes to host Windows.
# See: *
# *
[ $# -eq 0 ] && { echo "usage: open [path on NTFS] | [--copy [path on WSL]]"; exit 1; }
if [ $1 = "--copy" ]; then
if [ -z "$2" ]; then
echo "usage: open [--copy [path on WSL]]"; exit 1;
mkdir -vp /mnt/c/WSLTemp
cp -v $2 /mnt/c/WSLTemp/
f="$(basename -- $2)" # get just the filename
cd /mnt/c # cd to C: drive to supress cmd warnings about not being on the right path
cmd.exe /c start "" c:\\WSLTemp\\$f
if [ `stat --file-system --format=%T $1` = "v9fs" ]; then # v9fs check here isn't perfect, but works for now
cmd.exe /c start "" $1
echo "Windows applications cannot access the WSL filesystem, if you want to open this file with a Windows application anyway, re-run open with the --copy argument to copy the file to C:\WSLTemp on the host filesystem. Modifications to this file will not be saved."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment