Bash Command seq Regular Files Sequential Generation

Generating Regular Files Sequentially with Bash seq Command

This article introduces how to generate text content files regularly using the seq command in Bash, the Linux command line language.

Shou Arisaka
2 min read
Oct 3, 2025

Generating Regular Files Sequentially with Bash seq Command

This article introduces how to regularly generate files with content using the seq command in Bash, the Linux command line language.

Procedure

When you execute the following command, files numbered from 1 to 3 (1.txt, 2.txt, 3.txt) are generated, and each file contains its corresponding number.

ASUS:/mnt/c/pg/$ seq 1 3 | xargs -I {} bash -c "echo {} > {}.txt"
ASUS:/mnt/c/pg/$ ls
1.txt  2.txt  3.txt
ASUS:/mnt/c/pg/$ cat 1.txt 2.txt 3.txt
1
2
3

Command Details

  1. seq 1 3:

    • Outputs consecutive numbers from 1 to 3.
  2. xargs -I {} bash -c "echo {} > {}.txt":

    • The xargs command receives the output from the seq command and executes the echo command for each number.
    • -I {} is a placeholder for xargs, where each number is inserted.
    • bash -c "echo {} > {}.txt" is a Bash command that uses each number as a filename and writes that number to the file.

Verifying the Results

After executing the command, files are generated as follows, with each file containing its corresponding number:

ASUS:/mnt/c/pg/$ ls
1.txt  2.txt  3.txt
ASUS:/mnt/c/pg/$ cat 1.txt 2.txt 3.txt
1
2
3

This confirms how to regularly generate files with content. For more detailed usage examples and applications, please refer to Bash documentation and related resources.

Share this article

Shou Arisaka Oct 3, 2025

๐Ÿ”— Copy Links