The Linux seq command can generate lists of numbers and at lightning speed. It's easy to use and flexible, too. Credit: Jamie One of the easiest ways to generate a list of numbers in Linux is to use the seq (sequence) command. In its simplest form, seq will take a single number and then list all the numbers from 1 to that number. For example: $ seq 5 1 2 3 4 5 Unless directed otherwise, seq always starts with 1. You can start a sequence with a different number by inserting it before the final number. $ seq 3 5 3 4 5 Specifying an increment You can also specify an increment. Say you want to list multiples of 3. Specify your starting point (first 3 in this example), increment (second 3) and end point (18). $ seq 3 3 18 3 6 9 12 15 18 You can elect to go from larger to smaller numbers by using a negative increment (i.e., a decrement). $ seq 18 -3 3 18 15 12 9 6 3 The seq command is also very fast. You can probably generate a list of a million numbers in under 10 seconds. $ time seq 1000000 1 2 3 … … 999998 999999 1000000 real 0m9.290s Using a separator Another very useful option is to use a separator. Instead of listing a single number on each line, you can insert commas, colons or some other characters. The -s option followed by the character you wish to use. $ seq -s: 3 3 18 3:6:9:12:15:18 In fact, if you simply want your numbers to be listed on a single line, you can use a blank as your separator in place of the default linefeed. $ seq -s' ' 3 3 18 3 6 9 12 15 18 Getting to the math It may seem like a big leap to go from generating a sequence of numbers to doing math, but given the right separators, seq can easily prepare calculations that you can pass to bc. For example: $ seq -s* 5 | bc 120 What is going on in this command? Let’s take a look. First, seq is generating a list of numbers and using * as the separator. $ seq -s* 5 1*2*3*4*5 It’s then passing the string to the calculator (bc) which promptly multiplies the numbers. And you can do a fairly extensive calculation in a fraction of a second. $ time seq -s* 117 | bc 39699371608087208954019596294986306477904063601683223011297484643104 22041758630649341780708631240196854767624444057168110272995649603642 560353748940315749184568295424000000000000000000000000000 real 0m0.003s user 0m0.004s sys 0m0.000s Limitations You only get to choose one separator, so your calculations will be very limited. Use bc by itself for more complicated math. In addition, seq only works with numbers. To generate a sequence of single letters, use a command like this instead: $ echo {a..g} a b c d e f g Related content how-to How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe