迹忆客 专注技术分享

当前位置:主页 > 学无止境 > 操作系统 >

从命令行重新加载 .bash_profile

作者:迹忆客 最近更新:2023/06/10 浏览次数:

在 Shell 中,.bash_profile 用于自定义用户设置的配置。 它存储在根目录或主目录中,并且大部分对其他用户隐藏。

这个文件保存了shell的所有配置,也被认为是配置脚本。 它包括变量规范、导出变量等。

本文将展示我们如何在 macOS 中创建、删除和编辑 .bash_profile。 我们将通过必要的命令逐步学习它们。


创建 .bash_profile

在这部分,我们将学习如何创建 .bash_profile。 为此,我们将使用以下命令:

touch .bash_profile

现在,当我们完成创建 .bash_profile 后,我们可以使用以下命令检查文件:

ls -la

执行此命令后,您将获得如下所示的输出:

total 16
drwxr-xr-x 1 author author 4096 Aug  7 11:42 .
drwxr-xr-x 1 root   root   4096 Nov  1  2021 ..
-rw------- 1 author author 5378 Aug  6 01:46 .bash_history
-rw-r--r-- 1 author author  220 Nov  1  2021 .bash_logout
-rw-r--r-- 1 author author    0 Aug  7 11:42 .bash_profile
-rw-r--r-- 1 author author 3771 Nov  1  2021 .bashrc
drwx------ 1 author author 4096 Dec 18  2021 .cache
drwx------ 1 author author 4096 Dec 18  2021 .config
drwx------ 1 author author 4096 Dec 18  2021 .dbus
drwxr-xr-x 1 author author 4096 Nov  1  2021 .landscape
-rw-r--r-- 1 author author    0 Aug  7 11:41 .motd_shown
-rw-r--r-- 1 author author  807 Nov  1  2021 .profile
-rw-r--r-- 1 author author    0 Nov 29  2021 .sudo_as_admin_successful
-rw-r--r-- 1 author author    0 Jul  6 15:26 disk_usage.txt

在这里,您可以看到列出的 .bash_profile。


编辑并重新加载 .bash_profile

我们成功创建了 .bash_profile。 现在,是时候对其进行一些修改了。

要修改 .bash_profile,您可以使用 nono 编辑器。 您可以按照以下命令使用 nono 编辑器打开 .bash_profile。

nano .bash_profile

当我们修改完 .bash_profile 文件后,我们需要重新加载该文件以使自定义生效。 为此,我们可以使用以下两个命令中的任何一个。

source .bash_profile

或者我们可以使用,

source ~/.bash_profile

现在,我们完成了 .bash_profile 的创建和修改。 我们是按照命令去做的; 您可以使用任何文本编辑器手动完成。

请注意 ,本文中使用的所有代码都是用 Bash 编写的。 它只能在 Linux Shell 环境中运行。

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便