如何修改WSL Ubuntu的/home/ubuntu文件?Windows下如何定位该目录并编辑?
Hey there! Let's tackle your two WSL questions one by one—these are super common scenarios, so you're definitely not alone here.
1. How to modify files in /home/ubuntu
You've got a couple straightforward options here:
- Edit directly in WSL bash: Use a terminal-based editor like
nano(beginner-friendly) orvim. For example, to edit a file namedtest.txt, run:
Once you're done editing, pressnano /home/ubuntu/test.txtCtrl+Oto save, thenCtrl+Xto exit. Forvim, useito enter insert mode,Escto exit edit mode, then:wqto save and quit. - Edit from Windows (ties into your second question): You can access the
/home/ubuntudirectory directly from Windows File Explorer and use Notepad++ to edit files—keep reading for the step-by-step.
2. Finding /home/ubuntu in Windows & editing with Notepad++
Absolutely, this is totally feasible! WSL provides a seamless way to access its file system from Windows. Here's how:
- Open Windows File Explorer (press
Win+E). - In the address bar at the top, type
\\wsl$\Ubuntu\home\ubuntuand hit Enter.Note: If your WSL distribution has a different name (e.g., Ubuntu-22.04), replace
Ubuntuwith your actual distro name. You can check the name by runningwsl -lin a Windows Command Prompt or PowerShell. - Once you're in this folder, you'll see all the files and folders you created in WSL's
/home/ubuntudirectory. - Now you can:
- Drag and drop files directly into Notepad++ to edit them.
- Open Notepad++, go to File > Open, navigate to the
\\wsl$\Ubuntu\home\ubuntupath, select your file, and start editing. Any changes you save in Notepad++ will immediately show up in WSL bash.
Important Note
Never try to modify WSL's underlying virtual disk file (usually tucked away in C:\Users\<YourWindowsUsername>\AppData\Local\Packages\CanonicalGroupLimited...\LocalState\ext4.vhdx) directly. Always use the \\wsl$\ path to access WSL files from Windows—this ensures your file system stays intact and changes sync properly between WSL and Windows.
内容的提问来源于stack exchange,提问作者JBarros35

