Ubuntu .bashrc / .profile

.bashrc

问题描述

如果不小心在更改环境变量文件 ~/.bashrc 时出现将文件内容覆盖的情况,比如 echo hello world > ~/.bashrc 没有使用添加模式而是覆盖模式.

NOTE:非覆盖情况下,不推荐本文的方法.

解决方案

用系统中存储的 .bashrc 备份文件恢复到 ~/ 目录下,执行:

cp  /etc/skel/.bashrc   ~/

其中,/etc/skel是Ubuntu的各种初始配置文件的存放目录.

.profile

配置 ~/.bashrc 后下次登录 shell 无效

vi ~/.profile

if [ -s ~/.bashrc ]; then
    source ~/.bashrc;
fi

source .profile

附一份默认的 ~/.profile

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

/root/.profile

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n 2> /dev/null || true