Fortune (Unix)

Last updated
fortune
Original author(s) Ken Arnold
Initial release1979;45 years ago (1979)
Repository
Written in C
Operating system Unix, Unix-like, Plan 9, Inferno
Type Command
License Plan 9: MIT License

fortune is a program that displays a pseudorandom message from a database of quotations. Early versions of the program appeared in Version 7 Unix in 1979. [1] The most common version on modern systems is the BSD fortune, originally written by Ken Arnold. [2] Distributions of fortune are usually bundled with a collection of themed files, containing sayings like those found on fortune cookies (hence the name), quotations from famous people, jokes, or poetry.

Contents

fortune is predominantly found on Unix-like systems, but clients for other platforms also exist. [3] Often, users on text-mode Unix terminals will place this command into either their .profile or .logout files to display them at logon and logout, respectively. It is also used to generate text input for certain XScreenSaver modes. It is possible to pipe fortune into the cowsay command, to add more humor to the dialog.

Content

Most Unix systems use fortunes which are slanted heavily toward the user base of Unix, and thus contain many obscure jokes about computer science and computer programming. Other favoured sources include quotations from science fiction ( Star Trek , The Cyberiad , Doctor Who , The Hitchhiker's Guide to the Galaxy , etc.), Zippy the Pinhead, and the writings of Ambrose Bierce and Dave Barry. [4] Most fortune collections also include a wide variety of more conventionally sourced quotations, jokes, and other short passages. A few distributions include "offensive" dicta, which require the -a or -o options to be passed for viewing. These fortunes often include rude humor and profanity, personal attacks, and controversial comments about religion. Sometimes they are provided by another package, however as of FreeBSD 10.0 the offensive dicta have been removed completely. [5] As of November 2017, the quotations (with the exception of tips relevant to system operation) have been removed from FreeBSD entirely after user complaints regarding quotations from Adolf Hitler being contained in some of the files. [6] The exact fortunes vary between each type of Unix, however there seems to be a strong overlap between the FreeBSD and OpenBSD fortune files. The Plan 9 fortune files seem to be much shorter, with many just on 1 line, and the 'offensive' dicta is much stronger. Most Linux distributions, such as Debian (and its derivatives), choose the FreeBSD fortunes to put in their fortune packages, that can be installed through the package manager.

Purpose

One of the included fortunes, from the "goedel" collection of fortunes about fortune itself, sums up the purpose of the program:

Has anyone realized that the purpose of the fortune cookie program is to
defuse project tensions? When did you ever see a cheerful cookie, a
non-cynical, or even an informative cookie?
  Perhaps inadvertently, we have a channel for our aggressions. This
still begs the question of whether[sic] the cookie releases the pressure or only
serves to blunt the warning signs.

  Long live the revolution!
  Have a nice day.

The original fortune program could be used for the more general task of picking up a random line from a plain-text file. The example of such use is given in the rc documentation Archived 2014-09-08 at the Wayback Machine . However, in most modern Unix systems fortune cannot be used this way, since they use an ad hoc file format for fortune files to allow multiline aphorisms.

Fortune files

Conventional versions of fortune use two files for each quotation list: a text file with quotations, each separated by the character "%" on its own line, and a random-access data file generated by the strfile(1) program. Alternative implementations, including those made for display on Web pages, typically use only the text file.

Common options

Several common options exist that change the way command-line versions of fortune behave:

OptionAction
-aChoose from all databases, regardless of whether they are considered "offensive" or not
-eMake the probability of choosing a fortune file equal to that of all other files
-fPrint out a list of all fortune files that would have been searched, but do not print a fortune
-iWhen used with -m, make regular expression searching case-insensitive
-lUse only quotations longer than the length specified with -n, or 160 characters if -n is not used
-m [pattern]Print all fortunes matching the regular expression specified in [pattern]
-n [length]Override the length used by -l and -s to determine "long" and "short" messages (default 160 characters)
-oChoose only from "offensive" databases
-sUse only quotations shorter than the length specified with -n, or 160 characters if -n is not used
-wWait for a period of time before terminating; useful for situations in which a fortune needs to be read before the screen is cleared

See also

Related Research Articles

<span class="mw-page-title-main">Unix shell</span> Command-line interpreter for Unix operating system

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

man page Unix software documentation

A man page is a form of software documentation usually found on a Unix or Unix-like operating system. Topics covered include computer programs, formal standards and conventions, and even abstract concepts. A user may invoke a man page by issuing the man command.

tcsh Unix shell based on and compatible with the C shell

tcsh is a Unix shell based on and backward compatible with the C shell (csh).

In software development, Make is a build automation tool that builds executable programs and libraries from source code by reading files called makefiles which specify how to derive the target program. Though integrated development environments and language-specific compiler features can also be used to manage a build process, Make remains widely used, especially in Unix and Unix-like operating systems.

<span class="mw-page-title-main">GoboLinux</span> Linux distribution

GoboLinux is a Linux distribution whose most prominent feature is a reorganization of the traditional Linux file system. Rather than following the Filesystem Hierarchy Standard like most Unix-like systems, each program in a GoboLinux system has its own subdirectory tree, where all of its files may be found. Thus, a program "Foo" has all of its specific files and libraries in /Programs/Foo, under the corresponding version of this program at hand. For example, the commonly known GCC compiler suite version 8.1.0, would reside under the directory /Programs/GCC/8.1.0.

The Filesystem Hierarchy Standard (FHS) is a reference describing the conventions used for the layout of Unix-like systems. It has been made popular by its use in Linux distributions, but it is used by other Unix-like systems as well. It is maintained by the Linux Foundation. The latest version is 3.0, released on 3 June 2015.

Info-ZIP is a set of open-source software to handle ZIP archives. It has been in circulation since 1989. It consists of 4 separately-installable packages: the Zip and UnZip command-line utilities; and WiZ and MacZip, which are graphical user interfaces for archiving programs in Microsoft Windows and classic Mac OS, respectively.

chroot is an operation on Unix and Unix-like operating systems that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name files outside the designated directory tree. The term "chroot" may refer to the chroot(2) system call or the chroot(8) wrapper program. The modified environment is called a chroot jail.

pax is an archiving utility available for various operating systems and defined since 1995. Rather than sort out the incompatible options that have crept up between tar and cpio, along with their implementations across various versions of Unix, the IEEE designed new archive utility pax that could support various archive formats with useful options from both archivers. The pax command is available on Unix and Unix-like operating systems and on IBM i, and Microsoft Windows NT until Windows 2000.

less (Unix) Terminal pager

less is a terminal pager program on Unix, Windows, and Unix-like systems used to view the contents of a text file one screen at a time. It is similar to more, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, less does not need to read the entire file before starting, allowing for immediate viewing regardless of file size.

netcat Computer networking utility

netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP. The command is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and investigation tool, since it can produce almost any kind of connection its user could need and has a number of built-in capabilities.

file (command) Standard Unix program

The file command is a standard program of Unix and Unix-like operating systems for recognizing the type of data contained in a computer file.

Unix-like operating systems identify a user by a value called a user identifier, often abbreviated to user ID or UID. The UID, along with the group identifier (GID) and other access control criteria, is used to determine which system resources a user can access. The password file maps textual user names to UIDs. UIDs are stored in the inodes of the Unix file system, running processes, tar archives, and the now-obsolete Network Information Service. In POSIX-compliant environments, the shell command id gives the current user's UID, as well as more information such as the user name, primary user group and group identifier (GID).

<span class="mw-page-title-main">Joe's Own Editor</span>

JOE or Joe's Own Editor is an ncurses-based text editor for Unix systems, available under the GPL. It is designed to be easy to use.

mg (text editor)

mg, originally called MicroGnuEmacs, is a public-domain text editor that runs on Unix-like operating systems. It is based on MicroEMACS, but intended to more closely resemble GNU Emacs while still maintaining a small memory footprint and fast speed. An expanded version of the original is included as part of OpenBSD, where it is maintained, and snapshots of the OpenBSD version are available in the native package management trees of many other systems, including MacPorts, FreeBSD Ports, pkgsrc and Debian.

cowsay Program that generates ASCII pictures of a cow with a message

cowsay is a program that generates ASCII art pictures of a cow with a message. It can also generate pictures using pre-made images of other animals, such as Tux the Penguin, the Linux mascot. It is written in Perl. There is also a related program called cowthink, with cows with thought bubbles rather than speech bubbles. .cow files for cowsay exist which are able to produce different variants of "cows", with different kinds of "eyes", and so forth. It is sometimes used on IRC, desktop screenshots, and in software documentation. It is more or less a joke within hacker culture, but has been around long enough that its use is rather widespread. In 2007, it was highlighted as a Debian package of the day.

<span class="mw-page-title-main">Unix</span> Family of computer operating systems

Unix is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

The following outline is provided as an overview of and topical guide to the Perl programming language:

doas is a program to execute commands as another user. The system administrator can configure it to give specified users privileges to execute specified commands. It is free and open-source under the ISC license and available in Unix and Unix-like operating systems.

References

  1. "V7/usr/src/games/fortune.c". tuhs.org. Retrieved 2024-02-10.
  2. "[base] Contents of /head/usr.bin/fortune/fortune/fortune.c". svnweb.freebsd.org. Retrieved 2018-09-15. This code is derived from software contributed to Berkeley by Ken Arnold.
  3. "Jar of Fortune Files". fortunes.cat-v.org.
  4. "Debian Sources: fortune 1:1.99.1-7, "datfiles" folder". sources.debian.org. Retrieved 2018-09-15.
  5. "Fortune - removal log". FreeBSD SVN. FreeBSD. 2013-03-12. Retrieved 2014-06-14.
  6. "[base] Revision 325828". svnweb.freebsd.org. 2017-11-14. Retrieved 2018-04-14.