SSH连接中的颜色


Answers:


3

阅读“ Beyond Linux From Scratch”一书中的dircolors.sh小节:

该脚本使用~/.dircolors/etc/dircolors文件控制目录列表中文件名的颜色。它们控制ls --color之类的东西的彩色输出。本节末尾将介绍如何初始化这些文件。

cat > /etc/profile.d/dircolors.sh << "EOF"
# Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
        eval $(dircolors -b /etc/dircolors)

        if [ -f "$HOME/.dircolors" ] ; then
                eval $(dircolors -b $HOME/.dircolors)
        fi
fi
alias ls='ls --color=auto'
alias grep='grep --color=auto'
EOF

9
你能扩大一点答案吗?这个问题有2800个观点,这将是一个很好的补充。
slhck 2012年

Fedora 20还带有colorls.sh脚本。
Cristian Ciupitu 2014年

3

结合使用/unix/9883/how-can-i-run-a-script-immediately-after-connecting-via-ssh和nik的答案,您可以执行以下操作:

ssh host.example.com -t '. /etc/profile; . ~/.profile; /bin/bash'

这将在登录时执行您的配置文件脚本,然后打开一个bash shell。您的配置文件脚本是定义颜色的地方。

或者,为了最大程度的方便,将以下内容添加到~/.ssh/config文件中:

Host *
  LocalCommand . /etc/profile; . ~/.profile; /bin/bash
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.