更改默认shell
在 Linux 系统中,设置默认 Shell 通常通过修改用户的 Shell 配置来实现。以下是两种常见的方法:
方法 1: 使用 chsh
命令
chsh
(change shell) 命令可以更改当前用户的默认 Shell。
-
查看系统中可用的 Shell 列表:
-
更改默认 Shell,例如将默认 Shell 更改为
bash
或zsh
: -
重新登录以使更改生效。
方法 2: 手动编辑 /etc/passwd
你也可以直接编辑 /etc/passwd
文件来更改 Shell。
-
打开
/etc/passwd
文件并找到你的用户名: -
找到类似以下的行:
-
修改最后一部分为你希望的 Shell 路径,例如
/bin/zsh
: -
保存文件并退出。
重新登录或重启后,你的默认 Shell 将被更改为新的设置。
检查更改
使用以下命令验证你的默认 Shell:
优化 bash
# ~/.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
# 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'
#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 -alF'
alias la='ls -A'
alias l='ls -CF'