Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/b136385c0aca1a855d5352a75c1ebbe1 to your computer and use it in GitHub Desktop.
Save MOOOWOOO/b136385c0aca1a855d5352a75c1ebbe1 to your computer and use it in GitHub Desktop.
create specified size file by random content
# coding: utf-8
__author__ = 'Jux.Liu'
import os
from subprocess import Popen
from time import sleep
cmd_new_file_multiline = 'base64 /dev/urandom 2>>/dev/null | head -c {filesize} > ./{size}{unit}_{file_no} && echo "" >> ./{size}{unit}_{file_no}'
cmd_new_file_one_line = 'tr -dc A-Za-z0-9 </dev/urandom 2>>/dev/null | head -c {filesize} > ./{size}{unit} && echo "" >> ./{size}{unit}'
cmd_one_file_multiline = 'base64 /dev/urandom 2>>/dev/null | head -c {filesize} >> ./{size}{unit}_{file_no} && echo "" >> ./{size}{unit}_{file_no}'
cmd_one_file_one_line = 'tr -dc A-Za-z0-9 </dev/urandom 2>>/dev/null | head -c {filesize} >> ./{size}{unit} && echo "" >> ./{size}{unit}'
cmd_new_line= ''
OneKB = 1024
units = {
"KB": 1,
"MB": 1024
}
loop_size = {
"KB": [1, 5, 10, 50, 100, 500],
# "MB": [1, 5]
}
cmd = cmd_one_file_one_line
loop_times = 100
for unit in units:
for size in loop_size.get(unit, []):
for i in range(loop_times):
# !!! large file will take times to create
# !!! and be careful of your memory
c = cmd.format(filesize=size * units[unit] * OneKB - 1, size=size, unit=unit, file_no=i)
os.system(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment