Rahul Sharma (Editor)

Seq (Unix)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

On Unix-like computer systems, seq is a utility for generating a sequence of numbers.

Contents

History

seq first appeared on 8th edition Research Unix in 1985, and was not adopted by other variants of Unix (such as commercial Unixes or BSD). Nevertheless, it was later adopted in Plan 9 from Bell Labs, and from there was copied into modern BSD descendants like FreeBSD. Another version of seq was written in 1994 by Ulrich Drepper, for GNU, and is now available on all Linux distributions as part of the GNU Core Utilities.

Functionality

In its most basic use case, seq N prints out all the integers from 1 to N in sequence. This was convenient as the Unix shell at the time, the Bourne shell had no primitives for iterating over numbers, and its "for" command could only iterate over a list of words. seq was therefore used to generate such a list, as in this example:

seq had additional options for controlling the start (not just end) of the numeric sequence, its increment (a floating point number), and the formatting of the number. GNU seq changed the name and meaning of the format option (from -p to -f) and added an option to control the separator between the numbers (-s, defaults to a newline).

With other alternatives available (e.g., expr), and with more recent shells adding builtin numeric iteration, seq is a rarely used tool today. In the modern Linux shell, bash, the above example can be more clearly rewritten as:

and more efficiently, without actually generating the whole sequence in advance, as

References

Seq (Unix) Wikipedia


Similar Topics