Seq (Unix)

Last updated
seq
Developer(s) AT&T Bell Laboratories
Initial releaseFebruary 1985;37 years ago (1985-02)
Operating system Unix, Unix-like, Plan 9
Platform Cross-platform
Type Command
License coreutils: GPLv3+

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 some 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. The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities. [1]

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:

# Remove file1 through file17:for n in`seq 17`do     rm "file$n"done

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 less commonly used today. In the modern Linux shell, bash, the above example can be alternatively written as:

for n in{1..17}do     rm "file$n"done

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

for((n=1; n<=17; n++))do     rm "file$n"done

Related Research Articles

sed is a Unix utility that parses and transforms text, using a simple, compact programming language. sed was developed from 1973 to 1974 by Lee E. McMahon of Bell Labs, and is available today for most operating systems. sed was based on the scripting features of the interactive editor ed and the earlier qed. sed was one of the earliest tools to support regular expressions, and remains in use for text processing, most notably with the substitution command. Popular alternative tools for plaintext string manipulation and "stream editing" include AWK and Perl.

In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to write data to sequential I/O devices with no file system of their own. The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization.

ls

In computing, ls is a command to list computer files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell. In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir command. The numerical computing environments MATLAB and GNU Octave include an ls function with similar functionality.

In software development, Make is a build automation tool that automatically 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.

In the Unix operating system, shar is an archive format created with the Unix shar utility. A shar file is a type of self-extracting archive, because it is a valid shell script, and executing it will recreate the files. To extract the files, only the standard Unix Bourne shell sh is usually required.

ln (Unix)

The ln command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple filenames to be associated with the same file since a hard link points to the inode of a given file, the data of which is stored on disk. On the other hand, symbolic links are special files that refer to other files by name.

The archiver, also known simply as ar, is a Unix utility that maintains groups of files as a single archive file. Today, ar is generally used only to create and update static library files that the link editor or linker uses and for generating .deb packages for the Debian family; it can be used to create archives for any purpose, but has been largely replaced by tar for purposes other than static libraries. An implementation of ar is included as one of the GNU Binutils.

xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.

dd is a command-line utility for Unix, Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files.

pax (command)

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 a new archive utility 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, Microsoft Windows NT, and Windows 2000.

cp (Unix)

In computing, cp is a command in various Unix and Unix-like operating systems for copying files and directories. The command has three principal modes of operation, expressed by the types of arguments presented to the program for copying a file to another file, one or more files to a directory, or for copying entire directories to another directory.

nl is a Unix utility for numbering lines, either from a file or from standard input, reproducing output on standard output.

In computing, kill is a command that is used in several popular operating systems to send signals to running processes.

rm (Unix)

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

yes (Unix) Unix command

yes is a command on Unix and Unix-like operating systems, which outputs an affirmative response, or a user-defined string of text, continuously until killed.

cpio is a general file archiver utility and its associated file format. It is primarily installed on Unix-like computer operating systems. The software utility was originally intended as a tape archiving program as part of the Programmer's Workbench (PWB/UNIX), and has been a component of virtually every Unix operating system released thereafter. Its name is derived from the phrase copy in and out, in close description of the program's use of standard input and standard output in its operation.

sort (Unix) Standard UNIX utility

In computing, sort is a standard command line program of Unix and Unix-like operating systems, that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. Sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as sort key. Blank space is the default field separator. The command supports a number of command-line options that can vary by implementation. For instance the "-r" flag will reverse the sort order.

The banner program on Unix and Unix-like operating systems outputs a large ASCII art version of the text that is supplied to it as its program arguments. One use of the command is to create highly visible separator pages for print jobs.

In Unix and Unix-like operating systems, printf is a shell builtin that formats and prints data.

cat (Unix)

cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to concatenate files. It has been ported to a number of operating systems.

References

  1. "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  1. seq manual page from 8th Edition Unix
  2. seq manual page from FreeBSD