【问题标题】:Bash script to generate multiple files with fixed size用于生成多个固定大小文件的 Bash 脚本
【发布时间】:2019-08-21 06:43:35
【问题描述】:

我需要一个简单的 bash 脚本或一行来生成多个固定大小的文件,我需要能够在文件中或通过输入选择站点和数字。

我尝试了在网上找到的解决方案,但它们要么是关于创建多个文件,要么是关于创建一个具有固定大小的文件,而不是两者兼而有之。

例如:

for i in {1..5}; do dd if=/dev/urandom bs=1024 count=50 of=test.bin

这仍然只创建一个文件,而不是多个。

【问题讨论】:

  • ;
  • touch file{1..5} && truncate -s 50K file{1..5}?

标签: bash file size fixed


【解决方案1】:

正如Tom K 所指出的,您的 for 循环存在问题。 它应该类似于

#!/bin/bash
for i in 1 2 3 4 5
do
   dd if=/dev/urandom bs=1024 count=50 of=test-${i}.bin
done

结果:

ll test-*
-rw-r--r-- 1 root root 50K Aug 20 23:48 test-1.bin
-rw-r--r-- 1 root root 50K Aug 20 23:48 test-2.bin
-rw-r--r-- 1 root root 50K Aug 20 23:48 test-3.bin
-rw-r--r-- 1 root root 50K Aug 20 23:48 test-4.bin
-rw-r--r-- 1 root root 50K Aug 20 23:48 test-5.bin

编辑。 如果您愿意,也可以在线访问:

for i in {1..5}; do dd if=/dev/urandom bs=1024 count=50 of=test-${i}.bin; done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多