FORTUNE(6)

πŸ’« FORTUNE(6) πŸ’«

okay so bestie, welcome to fortune(6) from the UNIX Reference Manual β€” yes that UNIX, the ancient one, and yes this page is gonna be a whole vibe πŸŽ€


🌸 NAME 🌸

fortune β€” print a random, hopefully interesting, adage πŸ’–


✨ SYNOPSIS ✨

fortune     [-acefilosw]
            [-n length]
            [-m pattern]
            [[n%] file/dir/all]

πŸ¦‹ DESCRIPTION πŸ¦‹

so when you run fortune with like, zero arguments, it just prints out a random epigram. that's it. that's the whole thing. iconic behavior honestly ✨

the epigrams are split into several categories, and each category is sub-divided into the ones that could potentially offend you and the ones that won't. yes bestie, they pre-sorted the chaos for us πŸ’…

πŸ“ Options πŸ“

the options are as follows, no cap:

  • -a β€” pick from all the lists of maxims, offensive and non-offensive both. (peep the -o option if you wanna know more about the offensive fortunes πŸ‘€)
  • -c β€” show you the cookie file that your fortune came from πŸͺ lowkey useful
  • -e β€” treat every fortune file as if it were the same size (there's a whole discussion about multiple files further down, keep reading babe)
  • -f β€” just print the list of files it would have searched, but doesn't actually print a fortune. it's giving window shopping πŸ›οΈ
  • -l β€” long dictums only. check -n to see how "long" is defined in this context
  • -m pattern β€” print out every fortune matching the basic regular expression pattern. the exact syntax of these expressions depends on how your system defines re_comp(3) or regcomp(3), but it should still be similar to the syntax you'd use in grep(1).

the fortunes go to standard output, while the names of the file each fortune came from get printed to standard error. you can redirect either or both, fr fr β€” and if standard output goes to a file, the result is a valid fortunes database file 🫢 if standard error also gets redirected to that same file, the result is still valid, but you'll have "bogus" fortunes in there, i.e. the filenames themselves, sitting in parentheses. this is genuinely useful if you wanna remove the gathered matches from their original files, since each filename-record will come right before the records from the file it names. iykyk πŸ’…

  • -n length β€” sets the longest fortune length (in characters) that still counts as "short" (default is 160). anything longer than that counts as "long". ⚠️ be careful bestie! if you set the length too short and then ask for short fortunes, or too long and ask for long ones, fortune goes into a never-ending thrash loop. like, never-ending. 😭
  • -o β€” choose only from the potentially offensive aphorisms. heads up: the -o option is ignored if you specify a fortune directory.

and like, please, please, please only request a potentially offensive fortune if and only if you believe, deep in your heart, that you're willing to be offended. (and that you'll just quit using -o rather than give us grief about it, okay? πŸ™ˆ)

as the quote goes:

... let us keep in mind the basic governing philosophy of The Brotherhood, as handsomely summarized in these words: we believe in healthy, hearty laughter -- at the expense of the whole human race, if needs be. Needs be. --H. Allen Smith, "Rude Jokes"
  • -s β€” short apothegms only. check -n for which fortunes count as "short"
  • -i β€” ignore case for -m patterns πŸ”€
  • -w β€” wait before terminating, for an amount of time calculated from the number of characters in the message. this is useful if it's executed as part of the logout procedure, so you can guarantee the message gets read before the screen clears 🌈

okay so you can also specify your own alternate sayings πŸ’– you can point at a specific file, a directory that contains one or more files, or the special word all which says "use all the standard databases." any of these can be preceded by a percentage β€” that's a number n between 0 and 100 inclusive, followed by a %. if you do that, there's an n percent probability that an adage gets picked from that file or directory. and if the percentages don't sum to 100 and there are specifications without percentages, the remaining percent applies to those files and/or directories, in which case the odds of picking from one of them are based on their relative sizes. math queen behavior πŸ’…

as an example, given two databases funny and not-funny, with funny twice as big (in number of fortunes, not raw file size), saying

fortune funny not-funny

gets you fortunes out of funny two-thirds of the time. and the command

fortune 90% funny 10% not-funny

picks 90% of its fortunes from funny (the 10% not-funny part is unnecessary, since 10% is all that's left anyway πŸŽ€).

the -e option says "consider all files equal," so

fortune -e funny not-funny

is equivalent to

fortune 50% funny 50% not-funny

this fortune also supports the BSD method of appending -o to database names to specify offensive fortunes πŸ‘‘ however, that's not how fortune stores them: offensive fortunes live in a separate directory without the -o infix. so a plain name (i.e., not a path to a file or directory) that ends in -o will be assumed to be an offensive database β€” its suffix gets stripped off and it gets searched in the offensive directory, even if neither the -a nor the -o option was specified. this feature isn't just for backwards-compatibility, it also lets users tell apart inoffensive and offensive databases that have the same name πŸ¦‹

for example, assuming there's a database named definitions in both the inoffensive and the potentially offensive collections, then this command will select an inoffensive definition 90% of the time, and a potentially offensive definition for the remaining 10%:

fortune 90% definitions definitions-o

🧚 FILES 🧚

note: these are the defaults as defined at compile time.
  • /usr/share/fortune β€” directory for innoffensive fortunes.
  • /usr/share/fortune/off β€” directory for offensive fortunes.

if a particular set of fortunes is particularly unwanted, there's an easy solution: delete the associated .dat file πŸ’€ this leaves the data intact in case the file's wanted later, but since fortune can't find the pointers file anymore, it just ignores the text file. ghosted. πŸ™ˆ


πŸ’€ BUGS πŸ’€

the division of fortunes into offensive and non-offensive by directory, rather than via the -o file infix, is not 100% compatible with original BSD fortune. even though the -o infix is recognised as referring to an offensive database, the offensive database files still need to be in a separate directory. the workaround, of course, is to move the -o files into the offensive directory (with or without renaming), and to use the -a option. periodt.

the supplied fortune databases have been attacked, in order to correct orthographical and grammatical errors, and particularly to reduce redundancy and repetition and redundancy. but especially to avoid repetitiousness. this has not been a complete success 😭 in the process, some fortunes may also have been lost. rip to those πŸ•―οΈ

the fortune databases are now divided into a larger number of smaller files, some organized by format (poetry, definitions), and some by content (religion, politics). there are parallel files in the main directory and in the offensive files directory (e.g., fortunes/definitions and fortunes/off/definitions). not all the potentially offensive fortunes are in the offensive fortunes files, nor are all the fortunes in the offensive files potentially offensive, probably, though a strong attempt has been made to achieve greater consistency. also, a better division might be made. ngl, they're aware πŸ˜…


πŸ‘‘ HISTORY πŸ‘‘

this version of fortune is based on the NetBSD fortune 1.4, but with a number of bug fixes and enhancements ✨

the original fortune/strfile format used a single file; strfile read the text file and converted it to null-delimited strings, which were stored after the table of pointers in the .dat file. by NetBSD fortune 1.4, this had changed to two separate files: the .dat file was only the header (the table of pointers, plus flags; see strfile.h), and the text strings were left in their own file. the potential problem with this is that the text file and header file may get out of synch 😬 but the advantage is that the text files can be easily edited without resorting to unstr, and there's a potential savings in disk space (on the assumption that the sysadmin kept both the .dat file with strings and the text file).

many of the enhancements made over the NetBSD version assumed a Linux system, and thus caused it to fail under other platforms, including BSD. the source code has since been made more generic, and currently works on SunOS 4.x as well as Linux, with support for more platforms expected in the future 🌈 note that some bugs were inadvertently discovered and fixed during this process 🫢

at a guess, a great many people have worked on this program, many without leaving attributions πŸ‘‘ we love them for it


🌈 SEE ALSO 🌈

re_comp(3), regcomp(3), strfile(1), unstr(1)


πŸ’– and that's the whole page bestie, slay πŸ’–

this lil cutie is BSD Experimental, dated 19 April 94 [May. 97] β€” go forth and get urself a random adage πŸŽ€βœ¨

πŸ“¦ where this page comes from