【问题标题】:How can I remove scripts that run by default when I open the Linux terminal? (WSL) [closed]如何删除打开 Linux 终端时默认运行的脚本? (WSL)[关闭]
【发布时间】:2021-04-17 15:06:54
【问题描述】:
我不小心创建了一个脚本,当我在 Windows 上打开 linux 终端时会自动运行。
我完全忘记了我在哪里创建这些文件,现在我不知道如何删除它们。
我是否可以删除这些脚本或将 Linux 终端重置为默认设置?
我在 Windows 上的 Ubuntu 上使用 Bash。
Terminal with automatic scripts
【问题讨论】:
标签:
linux
windows
bash
ubuntu
windows-subsystem-for-linux
【解决方案1】:
您要问的是如何find-out-what-scripts-are-being-run-by-bash-on-startup。该链接回答了这个问题,但这里是它的短处:
要找到所有这些,您可以运行:
echo exit | strace bash -li |& grep '^open'
(-li 表示登录 shell 交互;仅将 -i 用于交互式非登录 shell。)
这将显示 shell 打开或尝试打开的文件列表。在许多系统上,它们如下所示:
另外很高兴知道默认情况下通常会运行以下内容:
/etc/profile
-
/etc/profile.d/*(/etc/profile.d/ 中的各种脚本)
/home/<username>/.bash_profile
/home/<username>/.bash_login
/home/<username>/.profile
/home/<username>/.bashrc
-
/home/<username>/.bash_history(不是脚本。只需启用history 命令)
/usr/share/bash-completion/bash_completion
/etc/bash_completion.d/*
-
/etc/inputrc(定义键绑定;这不是脚本)
仅供参考:/home/<username>/ 在大多数系统上与~ 相同
对于上面提到的每个脚本,您可能想要检查它们是否正在调用另一个脚本... 一个简单的方法是对所有这些脚本进行 grep 搜索关键字,暗示它们正在调用另一个脚本(尽管@987654338 @ 已经显示)
您可能想要:
cat <script_name> | grep -e 'bash' -e 'source' -e '\.\/'
【解决方案2】:
在 WSL 终端中,我会尝试检查您是否正在调用 ~/.bashrc 或 ~/.bash_profile 中的启动文件。这些是启动新 BASH 会话时调用的典型点文件。在您的情况下,请在这些文件中查找对 /bin/brew 的调用(或可能调用 brew 的行)。