windows - 登录到适用于 Linux 的 Windows 子系统时如何自动运行命令

标签 windows ubuntu windows-subsystem-for-linux

我有一个在 Windows 10 计算机上的 WSL 2 中运行的 Ubuntu 20.04。
每次登录 Ubuntu 时,我都必须手动执行这四行,将其一一粘贴到 Windows 10 终端中。

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig

sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target

exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME

sudo /etc/init.d/xrdp start
我可以知道是否有办法跳过这个手动过程?

最佳答案

每当您打开终端时,您都可以使用 .bashrc 文件执行命令。它应该位于 $HOME 目录。

cd $HOME
nano .bashrc
将命令放在文件末尾,按 ctl+x 然后按 y 保存。

关于windows - 登录到适用于 Linux 的 Windows 子系统时如何自动运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63687253/

相关文章:

windows - 如何在 Windows x64 上使用 openSSL 和 nghttp2 编译 cURL?

node.js - 适用于 Windows 和 Ubuntu 的 NodeJS exec() 命令

windows - 使用 Strawberry Perl 安装模块

c - Linux 中 timersub() 函数的隐式声明 - 我必须定义什么?

python - 如何修复 pip : cannot import name main?(pip 已安装并且 pip3 工作正常)

python - 为什么 Visual Studio Code 无法识别我的 WSL bash python?

bash - 在 bash 中运行 echo 时获取斜线是目录错误

emacs - 键盘输入如何通过Windows终端和WSL2传输

python - 如何在Windows 10上连接web2py和mysql

bash - apt-get install tzdata 非交互式