{"id":951,"date":"2010-09-07T16:28:59","date_gmt":"2010-09-07T21:28:59","guid":{"rendered":"http:\/\/emresaglam.com\/blog\/?p=951"},"modified":"2010-09-07T16:30:27","modified_gmt":"2010-09-07T21:30:27","slug":"creating-random-files","status":"publish","type":"post","link":"https:\/\/emresaglam.com\/blog\/blog\/2010\/09\/07\/creating-random-files\/","title":{"rendered":"Creating random files."},"content":{"rendered":"<p>Here is a bash script to create 100 random files with random sizes smaller than 400KB. I needed this to quickly generate 100 files to use it on a stress test.<\/p>\n<p><code>for ((i=1;i&lt;101;i++)); do<br \/>\nsize=`expr $RANDOM % 400`<br \/>\ndd if=\/dev\/urandom of=\/tmp\/testfile.$i bs=1024 count=$size<br \/>\ndone<\/code><\/p>\n<p>Explanation:<\/p>\n<p>The for loop is pretty straightforward, it counts from 1 to 100.<\/p>\n<p><code>size=`expr $RANDOM % 400`<\/code><\/p>\n<p>This line generates a random number between 0 &#8211; 399<\/p>\n<p><code>dd if=\/dev\/urandom of=\/tmp\/testfile.$i bs=1024 count=$size<\/code><\/p>\n<p>This line generates a file with blocksize (bs \/ not bullsh!t) 1024 times the random number that we generated. The input for that file is the special urandom device in linux. (It&#8217;s the random number generator for the linux kernel)<br \/>\nThe name of the file is also straightforward.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a bash script to create 100 random files with random sizes smaller than 400KB. I needed this to quickly generate 100 files to use it on a stress test. for ((i=1;i&lt;101;i++)); do size=`expr $RANDOM % 400` dd if=\/dev\/urandom of=\/tmp\/testfile.$i bs=1024 count=$size done Explanation: The for loop is pretty straightforward, it counts from 1 &hellip; <a href=\"https:\/\/emresaglam.com\/blog\/blog\/2010\/09\/07\/creating-random-files\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Creating random files.<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[11,9],"_links":{"self":[{"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/posts\/951"}],"collection":[{"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/comments?post=951"}],"version-history":[{"count":3,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/posts\/951\/revisions"}],"predecessor-version":[{"id":954,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/posts\/951\/revisions\/954"}],"wp:attachment":[{"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/media?parent=951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/categories?post=951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emresaglam.com\/blog\/wp-json\/wp\/v2\/tags?post=951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}