.bashrc在WSL上的什么位置?

时间:2019-04-07 09:15:01

标签: bash ubuntu windows-subsystem-for-linux

我正在使用Windows Subsystem for Linux,并试图找到终端的.bashrc文件。

其他线程通常表示两个位置之一:

C:\Users\USERNAME\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\{LINUXUSER}\

C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME

在我的计算机上,Local文件夹不包含Lxss子目录,因此消除了第二个选项,而home文件夹不包含任何内容,因此消除了第一个选项。在哪里可以找到.bashrc?

2 个答案:

答案 0 :(得分:-1)

因此,显然WSL在默认情况下不会创建用户。

可以如下设置一个

$ sudo adduser newuser # new user to play with, creates in /home/newuser like your default
$ sudo cp -aR /home/newuser /mnt/c/Users/<you>
$ sudo echo "echo 'running bashrc'" >> /mnt/c/Users/<you>/newuser/.bashrc
$ sudo usermod -d /mnt/c/Users/<you>/newuser newuser

完成此操作后,您可以在该用户的主目录中编辑.bashrc配置文件

ubuntu看到的是/mnt/c/Users/<you>/newuser/.bashrc,Windows看到的是C:\Users\<you>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\newuser\.bashrc

或者,您可以将.bash_profile放在C:\Users\<you>

中,而不是创建ubuntu用户。

有关更多信息,请参见此线程:https://github.com/Microsoft/WSL/issues/2612

答案 1 :(得分:-1)

@quantumbutterfly's answer is incorrect. The linked thread on github relates to people finding that their .bashrc was not run after moving their home directory.

WSL does create a default user. You do that as the last part of the setup.

You should be able to start up a WSL session and create a .bashrc in your home directory (~).

If you want to know where that file exists in Windows, just type the following: wslpath -aw ~.

If you are having trouble getting your .bashrc sourced after moving your home directory, the usermod referenced in quantum's post is likely all you need.

Other workarounds include:

  • Create a .bash_profile in your home directory and include source ~/.bashrc at the end of it.
  • Edit the bash on Ubuntu on Windows shortcut and add --rcfile ~/.bashrc to the end of the command. For example: C:\Windows\System32\bash.exe ~ --rcfile ~/.bashrc