HomeLinuxHow To Create a Large 1GB or 10GB File in Linux System

How To Create a Large 1GB or 10GB File in Linux System

Since Linux has been used widely for all data communication, networking, and data analysis, the demand for generating live data, static data, and dynamic data is also high. Analysts need to generate different types of data on both large and small scales to demonstrate a process. System admins also often need to generate files Larger than 10GB to check the stability of the system, hardware, and the OS itself. However, in Linux, you can create large files to meet all the demands of data with less effort and less time.

Create a Large File in Linux


The dummy data is often used to test the scalability and stability of a system. In Linux, there are several tools and commands that let you create larger files. The dd command is one of those commands that can create larger files with a reasonable time and without putting much pressure on the CPU. Based on the requirement of the data type and size, you can execute your dd command to create dummy data. In this post, we will see how to create larger files in a Linux system.

Step 1: Get To know with the dd Command in Linux


In Linux, the dd command mainly creates image files through the terminal command-line interface. Since this handy tool is pretty much handy for both Unix and Linux, we can use this command to create a large file in Linux. Here are the syntaxes of the dd command that we need to understand before we start creating files on Linux.

  • dd – The original purpose of this command is to copy and clone files.
  • df – This command lets you know the available free space on the Linux disk.
  • du – The du command allows you to show the disk analytics.
  • ls – This conventional ls command is well known for showing the list of files on the file system.

Step 2: Create a Large File in Linux with dd Command


To create a large file larger than 1GB or 10GB, we can run the following dd command on the terminal shell.

$ dd if=/dev/zero of=/path/to/file/storage/output.img [options]

The above command with the if syntax mentions the exact file size of the input volume, and the syntax explains the output destination and the volume. So, through this command, the output file will be the same as the input value. Here, we are executing the same command on our Linux system to check how it works. 

$ dd if=/dev/zero of=/home/ubuntupit/Large_File/output.img

Create large file in Linux

However, you can also execute the following command instead of the command mentioned above.

$ dd if=/dev/zero of=YOUR_IMAGE_FILE_NAME bs=1 count=0 seek=File_Size_HERE

Here, we are going to create a large file of 10GB on the Linux machine to demonstrate the process of creating a large file in Linux. Before executing the command, please ensure that your filesystem has enough free space to store the output file.

The following df command with a -H flag will let you know the free space on the disk.

$ df -H

Since we can see that we have enough space to create and store a large file on our Linux system, we may now execute the following command, which will create an image file of 10GB.

df -H command

$ dd if=/dev/zero of=10g.img bs=1 count=0 seek=10G

After we create the file, we may now need to verify if the file is successfully created or not by running a simple ls command.

$ ls -lh 10g.img
$ stat 10g.img

We can also verify the volume or the size of the newly created file through the GUI method. To do that, we will need to locate the file on the system. Then we need to right-click on the file and check the basic file info under the properties section.

Furthermore, the below-mentioned du command will display the size of the file on the Linux system with a null value as it’s still dummy data (image file) that you can still resize.

$ du -h 10g.img

Extra Tip 1: Use fallocate command to Create Large File


Since we have already seen how the dd command works, we can now get another command, which can also create a large file in Linux. Here comes the fallocate command on Linux that can pre-allocate the file size on the disk and create a file with that amount of data. To get a better understanding of this command, please have a look at the basic fallocate command given below.

fallocate command syntax

For instance, we can run the following command on the terminal shell to create a 1GB of large file in Linux.

fallocate -l 1G test.img

Now, to verify the data, we can perform the below-mentioned ls command to see if the fallocate command was successful in creating the 1GB file or not.

fallocate 1G test

$ ls -lh test.img

Extra Tip 2: Use truncate command to Create Large File


If you’re a database engineer or work with data, you probably are looking for the truncate SQL command, which is a very popular SQL command to create dummy data. In Linux, you can also use the truncate command to create a large 1Gb or more volume of data through the truncate command.

Please note that the truncate only creates zero-value data, so whatever you create through the truncate command, the actual filesystem still remains empty.

The below-mentioned truncate command will help you to understand how it works and how to create a large volume of data in Linux through this command.

#truncate -s 100GB 100-gb-file
#truncate -s 10G 10-gib-file

Final Words


Creating large data for demonstration is not a new thing, especially for those who work with Big Data and data integration tools. The entire post has been based on the Linux dd Data Definition (dd command), which can be used for data creating, data backup, data wipe, and restore. If you’re still keener about the dd command, you can always check the dd man page on Linux. In this post, we have discussed how to create a large 1GB or 10GB file in Linux.

Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

spot_img

Latest Post

Must Read