Use the simple `seq` generator to run commands repeatedly without writing long loops. 16.11.2025 | reading time: 3 min Want to run the same command many times without hand-coding a loop? `seq` generates number sequences that you can pipe into `xargs`, `sh -c` or other tools to execute commands repeatedly and predictably. Quick example: run five times Try this one-liner to run a short task five times and see the output; the first line shows the command and the following lines are the resulting output in sequence: ```$ seq 5 | xargs -I{} echo Run {} Run 1 Run 2 Run 3 Run 4 Run 5``` Create numbered files with padding Create five zero-padded files quickly; note the use of `-w` to pad numbers so filenames sort nicely and the `ls` output after the commands shows the created files: ```$ seq -w 1 5 | xargs -I{} touch file{}.txt $ ls file*.txt file01.txt file02.txt file03.txt file04.txt file05.txt``` Use increments and formatting Generate non-integer or formatted sequences with `seq`; here are two patterns, one for fractional steps and one using a format string: ```$ seq 0 0.25 1 | xargs -I{} echo {} 0 0.25 0.5 0.75 1 $ seq -f "%03g" 1 5 | xargs -I{} echo idx_{} idx_001 idx_002 idx_003 idx_004 idx_005``` Parallel runs and concurrency Combine `seq` with `xargs -P` or `parallel` to run many tasks concurrently; here is an example that launches up to four workers at once and prints when each job completes: ```$ seq 8 | xargs -n1 -P4 -I{} sh -c 'sleep 1; echo done {}' done 1 done 2 done 3 done 4 done 5 done 6 done 7 done 8``` When to prefer other approaches Use shell brace expansion for tiny local ranges because it avoids a subprocess, prefer `seq` when you need flexible start/step/end values, and choose higher-level tools when input is non-numeric or requires complex templating. Practical tips and gotchas Remember that `seq` is an external program provided by GNU coreutils on most Linux systems, so it handles floats and formats but may behave differently on minimal systems; also avoid word-splitting surprises by using `xargs -n1` or `-I{}` and quoting inside `sh -c` when command arguments contain spaces. Next steps for mastery Experiment by replacing `echo` with the real commands you need, try different `-f` formats for filenames, and combine `seq` with `find`, `sed` or small shell scripts to automate repetitive tasks efficiently. Join Bits & Bytes Academy First class LINUX exam preparation. scripting utilities processes