Windowsパスにおける「~」(チルダ)の意味
作成日:
Windows filesystem path
概要
Windowsのパスで「~」(チルダ)が現れるケースは主に2つある。
1. 8.3形式の短いファイル名
最も一般的なケース。Windowsは長いファイル名・フォルダ名を古いDOS互換の「8.3形式」に自動変換する。
| 長いファイル名 | 短いファイル名 |
|---|---|
Program Files | PROGRA~1 |
Program Files (x86) | PROGRA~2 |
Documents and Settings | DOCUME~1 |
LongFileName.txt | LONGFI~1.TXT |
詳細は Windows 8.3形式(Short File Name) を参照。
2. ホームディレクトリの省略形(Unix由来)
Unix/Linuxでは ~ はホームディレクトリを表す。以下のWindows環境でも同様に使える:
| 環境 | 対応状況 | 展開先 |
|---|---|---|
| Git Bash | 対応 | C:\Users\ユーザー名 |
| WSL | 対応 | /home/ユーザー名 |
| PowerShell | 一部対応 | $HOME に展開 |
| コマンドプロンプト(cmd.exe) | 非対応 | 認識されない |
使用例(Git Bash / WSL)
cd ~ # ホームディレクトリに移動
cd ~/Documents # ホーム配下のDocumentsに移動
ls ~/.ssh # SSH設定ディレクトリを表示
PowerShellでの動作
# PowerShellでは ~ が $HOME に展開される
cd ~
Get-Location # C:\Users\ユーザー名
見分け方
| パターン | 意味 | 例 |
|---|---|---|
XXXXXX~N | 8.3形式の短縮名 | PROGRA~1, LONGFI~2 |
~/path | ホームディレクトリからの相対パス | ~/Documents |
関連トピック
- Windows 8.3形式(Short File Name) - 8.3形式の詳細な仕組み