如何在 Linux 终端使用彩虹色
本文面向那些认为 Linux 命令行枯燥乏味,缺乏乐趣的人。为了创建有趣的彩色设置,可以使用 **lolcat** **工具**,它可以在 Linux 终端中生成彩虹色。Lolcat 工具适用于 Linux、BSD 和 OSX,其连接方式类似于 **cat** 命令。
安装 Lolcat
Lolcat 工具是 **Ruby** 编程语言中的一个 **gem**。因此,如果您想练习此技巧,则必须安装最新版本的 Ruby。
要安装 Ruby,请使用以下命令:
$ sudo apt-get install ruby
示例输出应如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386 libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386 libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386 libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386 libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386 libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386 libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386 libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386 libhx509-5-heimdal:i386 libice6:i386 libieee1284-3:i386 libjack-jackd2-0:i386 libjbig0:i386 libjpeg-turbo8:i386 libjpeg8:i386 libk5crypto3:i386 libkeyutils1:i386 libkrb5-26-heimdal:i386 libkrb5-3:i386 libkrb5support0:i386 liblcms2-2:i386 libldap-2.4-2:i386 libllvm3.6:i386 libltdl7:i386 libmouse-perl libmpg123-0:i386 libnet-dropbox-api-perl libogg0:i386 libopenal1:i386 liborc-0.4-0:i386 libosmesa6:i386 .................................
要验证 ruby 的版本,请使用以下命令:
$ sudo ruby --version
示例输出应如下所示:
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
要从 **git** 存储库获取 **Lolcat**,请使用以下命令:
$ wget https://github.com/busyloop/lolcat/archive/master.zip
示例输出应如下所示:
--2016-03-10 11:43:00-- https://github.com/busyloop/lolcat/archive/master.zip Resolving github.com (github.com)... 192.30.252.128 Connecting to github.com (github.com)|192.30.252.128|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/busyloop/lolcat/zip/master [following] --2016-03-10 11:43:01-- https://codeload.github.com/busyloop/lolcat/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.252.161 Connecting to codeload.github.com (codeload.github.com)|192.30.252.161|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/zip] Saving to: ‘master.zip’ [ <=> ] 2,03,272 234KB/s in 0.8s 2016-03-10 11:43:03 (234 KB/s) - ‘master.zip’ saved [203272]
要解压缩 master.zip 文件,请使用以下命令:
$ unzip master.zip
示例输出应如下所示:
Archive: master.zip 344e77462f8bab208f776b29bbcf63778aabd7af creating: lolcat-master/ extracting: lolcat-master/.gitignore inflating: lolcat-master/Gemfile inflating: lolcat-master/LICENSE inflating: lolcat-master/README.md extracting: lolcat-master/Rakefile creating: lolcat-master/ass/ inflating: lolcat-master/ass/screenshot.png creating: lolcat-master/bin/ inflating: lolcat-master/bin/lolcat creating: lolcat-master/lib/ inflating: lolcat-master/lib/lolcat.rb creating: lolcat-master/lib/lolcat/ inflating: lolcat-master/lib/lolcat/cat.rb inflating: lolcat-master/lib/lolcat/lol.rb extracting: lolcat-master/lib/lolcat/version.rb inflating: lolcat-master/lolcat.gemspec
要进入 **lolcat-master/bin** 目录,请使用以下命令:
$ cd lolcat-master/bin
要安装 **lolcat gem**,请使用以下命令:
$ gem install lolcat
示例输出应如下所示:
$ sudo gem install lolcat
示例输出应如下所示:
Fetching: paint-1.0.1.gem (100%) Fetching: trollop-2.1.2.gem (100%) Fetching: lolcat-42.1.43.gem (100%) Successfully installed paint-1.0.1 Successfully installed trollop-2.1.2 Successfully installed lolcat-42.1.43 3 gems installed Installing ri documentation for paint-1.0.1... Installing ri documentation for trollop-2.1.2... Installing ri documentation for lolcat-42.1.43... Installing RDoc documentation for paint-1.0.1... Installing RDoc documentation for trollop-2.1.2... Installing RDoc documentation for lolcat-42.1.43..
要获取 **Lolcat** 版本,请使用以下命令:
$ lolcat --version
示例输出应如下所示:
lolcat 42.1.43 (c)2011 [email protected]
要获取 lolcat 中可用的选项,请使用以下命令:
$ lolcat -h
示例输出应如下所示:
要使用 **Lolcat** 打印文本,请使用以下命令:
$ echo I love Tutorialspoint | lolcat $ figlet I love Tutorialspoint | lolcat
示例输出应如下所示:
在上述命令中,请注意我们使用了 **figlet**。
要安装 **figlet**,请使用以下命令:
$ sudo apt-get install figlet
要使用 **cowsay** 安装 **Lolcat**,请使用以下命令:
$ sudo apt-get install cowsay
示例输出应如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gcc-4.8-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libasound2-plugins:i386 libasyncns0:i386 libavahi-client3:i386 libavahi-common-data:i386 libavahi-common3:i386 libbit-vector-perl libcapi20-3:i386 libcarp-clan-perl libclass-method-modifiers-perl libcups2:i386 libdata-random-perl libdate-calc-perl libdate-calc-xs-perl libdrm-amdgpu1:i386 libdrm-intel1:i386 libdrm-nouveau2:i386 libdrm-radeon1:i386 libedit2:i386 libelf1:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libflac8:i386 libfontconfig1:i386 libfreetype6:i386 libgcrypt11:i386 libgd-perl libgd3:i386 libgif4:i386 libgl1-mesa-dri-lts-wily:i386 libgl1-mesa-glx-lts-wily:i386 libglapi-mesa-lts-wily:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnome2-gconf-perl libgnutls26:i386 libgpg-error0:i386 libgphoto2-6:i386 libgphoto2-port10:i386 libgssapi-krb5-2:i386 libgssapi3-heimdal:i386 libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386 ......................................................
**cowsay** 命令支持许多其他视觉图形动物,如下所示。
要获取动物列表,请使用以下命令:
$ cowsay -l
示例输出应如下所示:
Cow files in /usr/share/cowsay/cows: apt beavis.zen bong bud-frogs bunny calvin cheese cock cower daemon default dragon dragon-and-cow duck elephant elephant-in-snake eyes flaming-sheep ghostbusters gnu head-in hellokitty kiss kitty koala kosh luke-koala mech-and-cow meow milk moofasa moose mutilated pony pony-smaller ren sheep skeleton snowman sodomized-sheep stegosaurus stimpy suse three-eyes turkey turtle tux unipony unipony-smaller vader vader-koala www
例如,下面的 **小马** 图像是使用 lolcat 工具创建的。
使用以下命令获取输出:
$ cowsay -f pony I love tutorialspoint | lolcat
示例输出将类似于以下内容:
恭喜!现在,您知道“如何在 Linux 终端使用彩虹色”了。我们将在下一篇文章中学习更多关于此类命令的知识。继续关注!