最近在用PVE与PVE中的debian12模板时发现命令行中输入ls没有显示文件夹与文件的颜色 导致命令使用起来很不方便 因此查了一下解决方法,下面是具体操作
.bashrc文件是Bash shell的配置文件,它位于每个用户的主目录下,是一个隐藏文件。在Linux系统中,你可以通过以下路径找到它:
对于当前用户:~/.bashrc
这里的波浪号~代表当前登录用户的主目录。由于.bashrc文件是一个隐藏文件(文件名以点.开头),你可能需要使用带有-a(显示所有文件)选项的ls命令来查看它:
ls -a ~
这将列出当前用户主目录下的所有文件,包括隐藏文件。你会看到.bashrc在列出的文件中。
如果你想编辑.bashrc文件,可以使用文本编辑器,例如使用nano:
nano ~/.bashrc
或者使用vi或vim:
vi ~/.bashrc
接下来是我的.bashrc内容
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "$(dircolors)"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
根据我的文件中的内容发现颜色项被注释掉了,因此我们只需取消注释的颜色设置
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "$(dircolors)"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
保存 .bashrc 文件后,重新加载它以应用更改:
source ~/.bashrc
现在就完成啦!