自己的~/.bashrc 配置文件

本文档详细介绍了如何配置.bashrc文件,包括历史记录设置、终端提示符定制、颜色支持、ls别名和环境变量设定,特别是针对HLA、Android SDK和Java的路径设置。
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto -h'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alFh'
alias la='ls -Ah'
alias l='ls -CFh'
alias hla='hla -lmelf_i386'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

##### ADD By Gentoo User #######
HLA_HOME="/home/gentoo/HLA/usr/hla"
ANDROID_HOME="/opt/developmentTools/android-sdk-linux"
JAVA_HOME="/opt/jdk1.6.0_33"


PATH="$JAVA_HOME/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools"

CLASSPATH=".:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:"
PATH="$PATH:$HLA_HOME"
hlalib="$HLA_HOME/hlalib"
hlainc="$HLA_HOME/include"
hlatmp="$HLA_HOME/tmp"

export PATH
export hlalib
export hlainc
export hlatmp

<think>好的,我现在需要帮助用户解决如何配置或修改Linux的.bashrc文件。首先,我得回顾一下自己关于.bashrc的知识,确保信息准确。.bashrc是用户主目录下的一个隐藏文件,主要用于Bash shell的配置,比如设置别名、环境变量、函数等。修改这个文件可以个性化用户的shell环境,提高工作效率。 用户的需求是查找信息或编辑方法,所以需要分步骤说明。首先,应该告诉用户如何找到和打开这个文件。常用的方法是使用文本编辑器,比如nano、vim或者gedit。需要提醒用户.bashrc是隐藏文件,所以要用ls -a来查看。接下来,编辑完成后如何使配置生效,比如使用source命令或者重新打开终端。 然后,需要给出一些常见的配置示例,比如设置别名、修改路径、提示符样式等,这样用户有实际的参考。同时,注意事项也很重要,比如备份原文件,避免语法错误,区分不同配置文件的作用(如.bash_profile和.bashrc的区别)。 接下来,检查是否有相关的引用资料可以提供支持。根据用户提供的引用内容,引用1、2、4都提到了.bashrc的作用和修改方法,可以引用这些来增强回答的可信度。比如,在解释.bashrc的重要性时,可以引用[^1]和[^4]。 需要确保回答结构清晰,分步骤说明,并且符合用户的要求:使用中文,LaTeX格式正确,行内公式用$,独立公式用$$。不过在这个问题中可能用到的LaTeX不多,但如果有数学表达式的话要注意格式。例如,在说明路径时,可能需要使用$PATH,这时候要用$PATH$来表示。 还要生成相关问题,这部分需要考虑用户可能进一步的问题,比如如何设置永久环境变量,如何调试配置,或者不同shell之间的区别。根据常见问题,可以列出如修改后立即生效的方法、常见错误、不同配置文件差异等。 最后,检查是否有遗漏的要点,比如提醒用户权限问题,或者使用注释来组织.bashrc文件。确保所有信息准确,引用正确,并且语言自然流畅,符合用户的要求。</think>### 如何配置或修改 Linux 的 `.bashrc` 文件? #### 1. **定位和编辑 `.bashrc` 文件** - **文件位置**: `.bashrc` 位于用户主目录下(`~/.bashrc`),是隐藏文件。可使用以下命令查看: ```bash ls -a ~/ ``` - **编辑方法**: 使用文本编辑器(如 `nano`、`vim` 或图形化编辑器 `gedit`)打开文件: ```bash nano ~/.bashrc # 终端编辑 gedit ~/.bashrc & # 图形界面编辑 ``` - **生效修改**: 修改后需执行以下命令使配置立即生效: ```bash source ~/.bashrc ``` 或重新启动终端[^2][^3]。 --- #### 2. **常见配置示例** - **设置命令别名**: 简化常用命令: ```bash alias ll='ls -alF' alias update='sudo apt update && sudo apt upgrade' ``` - **自定义环境变量**: 添加软件路径或配置: ```bash export PATH="$PATH:/usr/local/custom/bin" export JAVA_HOME="/usr/lib/jvm/java-11-openjdk" ``` - **修改提示符样式**: 使用 `PS1` 变量自定义终端提示符: ```bash PS1='\[\e[32m\]\u@\h:\w\$\[\e[0m\] ' # 绿色提示符 ``` - **添加函数**: 定义常用功能函数: ```bash weather() { curl "wttr.in/$1" } ``` --- #### 3. **注意事项** - **备份文件**: 修改前建议备份原文件: ```bash cp ~/.bashrc ~/.bashrc.bak ``` - **避免语法错误**: 错误的语法可能导致终端无法正常启动。若出现问题,可通过其他终端会话恢复备份。 - **作用范围区分**: `.bashrc` 仅对当前用户的 **交互式非登录Shell** 生效。若需全局配置,可修改 `/etc/bash.bashrc`;登录Shell的配置需编辑 `~/.bash_profile` 或 `~/.profile`[^4]。 --- #### 4. **高级用法** - **条件判断**: 根据系统类型加载不同配置: ```bash if [ -f /etc/redhat-release ]; then alias install='sudo yum install' else alias install='sudo apt install' fi ``` - **加载外部脚本**: 将大型配置拆分到独立文件: ```bash if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值