Yes… No and Other Corners of Coreutils
About a decade ago, I wanted to do some deep program analysis on GNU Coreutils. The analysis didn’t get too far, but, in the process, I did become familiar with some lesser-known Coreutils functionality that’s come in handy surprisingly often since then, shared below.
Automating Responding to Prompts
yes program, by default, prints lines containing “y” endlessly
to its output. This is meant to automatically drive a process that
asks for repeated confirmations. Surprisingly,
yes can take
in which case, instead of “y,”
yes prints its arguments, in order,
separated by a single space between each. So, for example, you can
yes n to deny, rather than accept, all confirmation prompts.
My main use for
yes with arguments has nothing to do with
confirmation prompts, however. Rather, every now and then, some
process that sends mail goes haywire, creating a mess that needs to be
cleaned up via the
d key over and over to delete everything, I run
yes d | head -100 | mail.
Joining on Columns
program allows joining records by column, which can often eliminate
the need to import data into another system like a database or
Finding Common Lines
diff program for finding lines that differ between two files is
well known. When you want to know what lines two files have in
program outputs lines in a random order. This is useful, especially
in combination with
head, for getting a random sample.