How to: Change User’s bash profile under Linux / UNIX

本文详细介绍了如何编辑BASH shell的个人初始化文件 ~/.bash_profile 和 ~/.bashrc,以设置环境变量、创建别名和调整默认权限。还讨论了系统级配置文件 /etc/profile 的作用。了解这些设置对于优化开发环境至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Q. How do I change my own profile? How do I change profile for other users? How do I setup global profile for all users under BASH shell?

A.. You need to add user profile to ~/.bash_profile. It is the personal initialization file, executed for login shells. There is also ~/.bashrc file which is the individual per-interactive-shell startup file. Common uses for ~/.bash_profile are to set environment variables such as PATH, JAVA_HOME, create aliases for shell commands and set the default permissions for newly created files etc. The file ~/.bashrc is similar, with the exception that .bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.

Edit user .bash_profile file

Use vi command:
$ cd
$ vi .bash_profile

My same profile:

umask 022
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
fi
alias dironly='printf "%s\n" */'
alias dironlyv='echo */.'
alias dragon=~/bin/showMenu.pl
export PATH=/usr/lib/jvm/java-6-sun-1.6.0.00/bin:${PATH}

.bashrc vs .bash_profile files

Let us see the difference with these two scripts:

~/.bashrc file runs every time you open a new non-login bash shell such as xterm / aterm, and ~/.bash_profile runs only with login shells i.e when you first log in into system.

/etc/profile - System wide global profile

The /etc/profile file is systemwide initialization file, executed for login shells. You can edit file using vi (login as root):
# vi /etc/profile


reference:http://www.cyberciti.biz/faq/change-bash-profile/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值