HeatWare.net header image
HeatWare.net
TwitterRSSEmail
  • Home
  • Windows
    • Windows 8
    • Windows 7
    • Windows Vista
    • Windows XP
  • Linux/Unix
  • Mac
  • Mobile
    • Android
    • iOS
    • Phones (Help / Resources)
  • Software / Programming
    • Free Software
    • Programming – General
    • PHP
    • Ruby/Rails
    • Quality Assurance (QA)
    • Software – General
    • Software Help
    • Databases
  • Cool Websites
  • Other
    • Deals & Bargains
    • News
    • Video Games
    • Hardware
    • Electronics
  • About

6 comments / January 12, 2011 / sood / Linux/Unix

How to create a large number of files in Linux (thousands or millions)

Do you need an ultra fast way to create a large number of files in Linux? Perhaps, you are doing some load testing for an application and you need to create 1000 or even 1,000,000 files in the matter of seconds. Well, here is how to do it!

There are two parts to creating these files. First, is creating a single master file that contains the data that the thousands/millions files are based on. Second, splitting this master file into the total number of files that you require.

How to create the master file

  1. Determine the number of files and the size of each file that you require
  2. Multiply the total number of files times the size (in bytes). For example: If you want to create 10000 files that are 10 bytes each, do 10000 * 10 = 1,000,000. This represents the size of the master file that is needed.
  3. To create this master file, run the command:
  4. dd if=/dev/zero of=masterfile bs=1 count=1000000

  5. The above command will create a 1 MB file called ‘masterfile’. This file contains all 0’s. If you would like it to contain random binary data, use /dev/urandom

To split the master file into thousands of pieces

  1. Now that the master file is created, you can now use this to generate the desired 10,000 files that are 10 bytes each.
  2. Run the command:
  3. split -b 10 -a 10 masterfile

The -b option specifies the size in bytes of each file. The -a option defines the length of the filename of the new files +1 (-a 10 means create a 11 character long filename)

And that’s all there is to it! If you need help with any variation to this, please post it as a comment.

Related Posts

  • How to create MD5 Checksums and validate a file in Linux
  • Using Linux ‘head’ command to preview a file
  • Free Linux utility to convert PDF to Text file
  • How to Find Files Owned by Group(s) in Linux
  • How to append string/data to a file in Linux

Linux Linux/Unix

6 comments… add one
  1. w September 30, 2013, 12:48 am

    interesting!
    but
    10000 * 10 != 1,000,000

  2. w April 8, 2014, 4:17 am

    there is something wrong in your dd
    it should be

    bs=1000000 count=1
    not the other way around.

  3. core January 7, 2015, 10:17 am

    Thanks this is awesome thanks!

  4. Deano January 26, 2015, 10:53 pm

    Thanks very much!

  5. ktrisnake February 15, 2017, 12:14 am

    Useful!

  6. Nasir Haider November 12, 2018, 1:37 am

    Thanks a lot. It really helped.
    Just a little correction i.e. (100,000 * 10 = 1,000,000 ) instead of (10,000*10 = 1,000,000)

Cancel reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Why You Should Consider Diving Apps
  • How to Buy a Smartphone that Fits Your Budget
  • How to Overcome Frustrating PDF Stress
  • Convert PDF to Word: Easy, Reliable and Quality Conversion
  • PDF to Excel App ­ – A New Way of Handling Tricky Documents

Recent Comments

  • Valarie Walter on Basic Troubleshooting Steps for your Cell Phone
  • John Mists on A Brief History of Android OS
  • syarif on PostgreSQL: How to reload config settings without restarting database
  • Raghu on How to SSH to a server using Ruby – Part I
  • francisco clemente on Basic Troubleshooting Steps for your Cell Phone

Tags

ACSLS Android Bargain Cell Phones Cool Software Cool Websites Databases Deals Ebooks Facebook Free Software G2x Galaxy S5 iOS iPhone Kindle LG Linux Linux/Unix Mac Mobile mysql Office OpenStack OS X PHP Postgres PostgreSQL ruby Samsung Galaxy S6 Shell Smartphones Sun T-Mobile Tips Tips & Tricks Ubuntu Unix Virtualization VMWare Windows Windows 7 Windows 8 Windows Vista Windows XP

Latest Tweet

Follow @HeatwaredotNet

SP
@HeatwaredotNet

  • Why You Should Consider Diving Apps https://t.co/Is41cdUv2I #diving-apps
    about 6 years ago

All Categories

Other Links

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2015 — HeatWare