python - 如何创建 1000 个可用于测试脚本的文件?

标签 python bash shell perl scripting

我想用一些文本创建 1000 多个文本文件来测试脚本,如何使用 shell 脚本或 Perl 一次性创建这么多文本文件。请问有人能帮帮我吗?

最佳答案

for i in {0001..1000}
do
  echo "some text" > "file_${i}.txt"
done

或者如果你想使用 Python <2.6

for x in range(1000):
    open("file%03d.txt" % x,"w").write("some text")

关于python - 如何创建 1000 个可用于测试脚本的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2084832/

相关文章:

python - 在数据类型上使用 "switch"的 python 字典

python - React 不读取从 Flask GET 端点返回的 json

python - 为什么 eval() 在网络编译器中不起作用?

linux在管道后获取文件内容作为stdio

bash - 按时间戳命名目录选择要输出的目录

Python子进程: Unable to Escape Quotes

linux - 如何制作非交互式 shell 脚本

python - ModuleNotFoundError : No module named 'pandas' (jupyter notebook)

bash - 如何列出我的 shell 中定义的函数?

linux - 将过去 07 天的文件连接到 Shell 中的一个文件中