5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

wslpathコマンドで、Windowsパス⇔Linuxパスを相互変換する。

Last updated at Posted at 2022-05-13

使い方

WSL(Linux上)ではwslpath 'パス'
PowerShellではwsl wslpath "'パス'"を実行する。

Windows→Linux

WSL

$ wslpath ${Windowsのパス}
$ wslpath 'C:\Windows\Media'
/mnt/c/Windows/Media

PowerShell

> wsl wslpath "'${Windowsのパス}'"
> wsl wslpath "'C:\Windows\Media'"
/mnt/c/Windows/Media

Linux→Windows

WSL

$ wslpath -w ${Linuxのパス}
$ wslpath -w '/mnt/c/Windows/Media'
C:\Windows\Media

PowerShell

> wsl wslpath ${Linuxのパス}
> wsl wslpath -w /mnt/c/Windows/Media
C:\Windows\Media

マニュアル

Usage:
    -a    force result to absolute path format
    -u    translate from a Windows path to a WSL path (default)
    -w    translate from a WSL path to a Windows path
    -m    translate from a WSL path to a Windows path, with '/' instead of '\'

EX: wslpath 'c:\users'

注意点

PowerShellでは\のエスケープなどが必要

失敗例

> wsl wslpath 'C:\Windows\Media'
wslpath: C:WindowsMedia

良い例

> wsl wslpath 'C:\\Windows\\Media'
/mnt/c/Windows/Media

> wsl wslpath "'C:\Windows\Media'"
/mnt/c/Windows/Media

> wsl wslpath '"C:\Windows\Media"'
/mnt/c/Windows/Media

「PowerShellでは上手く動かないのか?」と悩んでいたところ、コメントにて間違いをご指摘いただきました。ありがとうございます。

5
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?