Skip to content

建立 2026-09-14 更新 2026-09-14

檔案系統

WSL 2 有兩套檔案系統:Linux 自己的磁碟,以及掛進來的 Windows 磁碟。工具在哪邊跑,檔案就放哪邊,速度差會非常明顯。

專案放哪

在 Linux 終端機開發(gitnpmpip、編譯器)時:

建議:  /home/你的名稱/projects/...
不要:  /mnt/c/Users/你的名稱/projects/...

/mnt/c 是 Windows 的 C:\。跨作業系統讀寫要經過轉譯層,git statusnpm install 會變慢一個數量級。官方建議見 Working across file systems

從 Windows 看 Linux 檔案,檔案總管位址列輸入:

\\wsl$

或較新的:

\\wsl.localhost\Ubuntu\home\你的名稱

在 Linux 裡開目前資料夾:

explorer.exe .

結尾的 . 代表「這裡」。也可以用 VS Code 的 WSL 擴充功能直接開 Linux 資料夾,見 VS Code

大小寫

Windows 預設不區分大小寫(Foo.txtfoo.txt 常被當成同一個);Linux 區分。專案若同時被兩邊碰到,避免只靠大小寫區分檔名。需要時可為特定資料夾開啟大小寫區分,細節見官方「Adjust case sensitivity」。

兩邊的指令可以互叫

在 PowerShell 跑 Linux:

wsl ls -la
wsl ls -la | findstr "git"

在 Ubuntu 跑 Windows 程式,檔名要加 .exe

notepad.exe notes.md
ipconfig.exe | grep IPv4
cmd.exe /C dir

這叫 interop。不想讓 Linux 叫 Windows 程式時,可在 wsl.conf 關掉,見 組態檔

環境變數若要在兩邊共享,使用特殊變數 WSLENV 列出要傳遞的名稱,並用 /p 等旗標轉換路徑格式。

官方短片

「在 WSL 裡如何存取電腦上的檔案」約 1 分 40 秒。

想理解 Windows 如何掛載 Linux 檔案,可看深度解析 How WSL accesses Linux files from Windows(約 25 分鐘),嵌入在 官方影音