如何为你的 Linux 终端带来好运

使用 fortune 实用程序将名言警句带到命令行。
156 位读者喜欢这篇文章。
Linux toy: fortune

Jason Baker

现在是十二月,如果你还没有找到让你心动的科技降临节日历,那么,也许这个可以帮到你。从现在到 24 号的每一天,我们都会为你带来一个不同的 Linux 命令行玩具。什么是命令行玩具?你可能会问。它可以是一个游戏或任何简单的消遣,为你的终端带来一点快乐。

你可能以前见过其中一些。我们也希望你能找到一些新的东西。无论如何,我们希望你跟随着玩得开心。

今天的玩具 fortune 是一个老玩具。它的版本可以追溯到 1980 年代,当时它包含在 Unix 中。我在 Fedora 中安装的版本是在 BSD 许可下提供的,我通过以下方式获取了它。

$ sudo dnf install fortune-mod

你的发行版可能有所不同。在某些发行版上,你可能需要将 fortunes 与 fortune 本身分开安装(尝试在你的软件包管理器中搜索“fortunes*”)。你也可以在 GitHub 上查看源代码。然后,只需运行 fortune 即可获得,嗯,一个 fortune。

$ fortune
"Time is an illusion.  Lunchtime doubly so."
-- Ford Prefect, _Hitchhiker's Guide to the Galaxy_

那么为什么你需要在终端中使用 fortunes 呢?当然是为了好玩。也许你想将它们添加到你系统每日消息中?

就我个人而言,我喜欢使用 fortune 命令作为内置的虚拟数据,当我在终端中使用它来解析文本时,尤其是在使用 正则表达式 时,并且想要一些简单的东西来尝试它。

例如,假设我正在使用 tr 命令测试一个转换,将字母 e 替换为数字 3。

$ fortune | tr 'eE' '3'
Unix 3xpr3ss:
All pass3ng3r bring a pi3c3 of th3 a3roplan3 and a box of tools with th3m to
th3 airport. Th3y gath3r on th3 tarmac, arguing constantly about what kind
of plan3 th3y want to build and how to put it tog3th3r. 3v3ntually, th3
pass3ng3rs split into groups and build s3v3ral diff3r3nt aircraft, but giv3
th3m all th3 sam3 nam3. Som3 pass3ng3rs actually r3ach th3ir d3stinations.
All pass3ng3rs b3li3v3 th3y got th3r3.

那么你的发行版附带哪些 fortunes 呢?查看你的 /usr/share/games/fortune 目录以找到所有这些。以下是我最喜欢的几个。

Never laugh at live dragons.
		-- Bilbo Baggins [J.R.R. Tolkien, "The Hobbit"]
I dunno, I dream in Perl sometimes...
             -- Larry Wall in  <8538@jpl-devvax.JPL.NASA.GOV>
I have an existential map.  It has "You are here" written all over it.
		-- Steven Wright

想要了解更多关于 fortune 的信息?你当然可以随时查看 man 手册以了解更多关于选项的信息,或者在 Wikipedia 上阅读更多关于该命令的历史。

你有没有最喜欢的命令行玩具,你认为我应该介绍一下?这个系列的日历大部分都已填满,但我还剩下几个空位。请在下面的评论中告诉我,我会查看一下。如果有空间,我会尝试将其包括在内。如果没有,但如果我收到一些好的投稿,我会在最后做一个荣誉提名总结。

查看昨天的玩具,通过你的 Linux 终端驾驶火车头,明天再回来看看另一个!

接下来阅读
标签
User profile image.
Jason 从 2013 年到 2022 年是 Opensource.com 的工作人员和红帽员工。此个人资料包含他那段时间与工作相关的文章。其他贡献可以在他的个人帐户中找到。

评论已关闭。

Creative Commons License本作品根据 Creative Commons Attribution-Share Alike 4.0 International License 获得许可。
© . All rights reserved.