LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2019, 02:54 AM   #1
Shozib
LQ Newbie
 
Registered: Jan 2019
Posts: 12

Rep: Reputation: Disabled
Question I want to create a dummy file of 1TB


Hi, everyone
As listed in the subject basically I want to create a large file in linux.
Currently I am using this command:
dd if=/dev/zero of=file.txt count=1024 bs=1024

to do that, it can create a file in some GBs like 7, 8 etc but I want to create a large file like 500GB or 1TB.

When I give a large number to the parameters "Count" and "bs"
I am having this error:
DD: Memory Exhausted by Input Buffer of Size Bytes (9Gib)

Can anyone please guide me in this regard. Or suggest me to use any other suitable way. I would be very thankful to you.

Thanks
Shozib
 
Old 07-23-2019, 03:13 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Depending on how you intend to use the file, "truncate" is probably best. Have a read of sparse_file.
 
1 members found this post helpful.
Old 07-23-2019, 06:08 AM   #3
mike acker
Member
 
Registered: Feb 2014
Location: Michigan
Distribution: Debian 10
Posts: 199

Rep: Reputation: Disabled
Code:
#include <stdio.h>
#include <string.h>

#define OUTPUT_SIZE_REQUEST 1000
#define OUTPUT_FILE_NAME cmd_line_arg[1]

	int main(int nof_args, char **cmd_line_arg);

	int main(int nof_args, char **cmd_line_arg)
	{
		FILE *text_out;
		char *test_text = "This has been a test. \n "
			"Had it been an actual alert you would not have received this message.\n";

		long int msg_size, total_output = 0;		puts(test_text);

		if (2==nof_args) ; else { puts ("Supply output file name on command line"); return(1); }
		
		text_out=fopen(OUTPUT_FILE_NAME,"w");

		if (NULL==text_out)
		{ printf("unable to open %s file for output\n", OUTPUT_FILE_NAME);
				return(2);	}
		else printf("%s file opened for output\n", OUTPUT_FILE_NAME);

		msg_size = strlen(test_text);

		do {	fputs(test_text,text_out);
		 	total_output+=msg_size; }
		while (total_output<OUTPUT_SIZE_REQUEST);

		printf("%d output characters written\n", total_output);

		fclose(text_out);
		return(0);

	}

Last edited by mike acker; 07-23-2019 at 06:12 AM.
 
1 members found this post helpful.
Old 07-23-2019, 06:20 AM   #4
Shozib
LQ Newbie
 
Registered: Jan 2019
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
Depending on how you intend to use the file, "truncate" is probably best. Have a read of sparse_file.
Alright, Thankyou for your prompt reply.
 
Old 07-23-2019, 07:07 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by mike acker View Post
Code:
#include <stdio.h>
#include <string.h>

#define OUTPUT_SIZE_REQUEST 1000
#define OUTPUT_FILE_NAME cmd_line_arg[1]

	int main(int nof_args, char **cmd_line_arg); // not needed

	int main(int nof_args, char **cmd_line_arg)
	{
		FILE *text_out;
		char *test_text = "This has been a test. \n "
			"Had it been an actual alert you would not have received this message.\n";

		long int msg_size, total_output = 0;		puts(test_text);

		if (2==nof_args) ; else { puts ("Supply output file name on command line"); return(1); }
		
		text_out=fopen(OUTPUT_FILE_NAME,"w");

		if (NULL==text_out)
		{ printf("unable to open %s file for output\n", OUTPUT_FILE_NAME);
				return(2);	}
		else printf("%s file opened for output\n", OUTPUT_FILE_NAME);

		msg_size = strlen(test_text);

		do {	fputs(test_text,text_out);
		 	total_output+=msg_size; }
		while (total_output<OUTPUT_SIZE_REQUEST);

		printf("%d output characters written\n", total_output);

		fclose(text_out);
		return(0);

	}
why did you defind main? that is the only function that I know that does not need to be defined, but has to be included or a program will not work.
 
Old 07-23-2019, 08:10 AM   #6
mike acker
Member
 
Registered: Feb 2014
Location: Michigan
Distribution: Debian 10
Posts: 199

Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
why did you defind main? that is the only function that I know that does not need to be defined, but has to be included or a program will not work.
leftover habit, probably.
the program works without the function definition.

the need for this:
Code:
#define _GNU_SOURCE /* include in order to use fcloseall() */
kinda threw me; I'm running Debian.10 -- and I had not needed that earlier.
 
Old 07-26-2019, 04:28 AM   #7
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
You could create the 1GB file and cat it to a new file >> append style 1000 times. Or 1024. A simple one liner bash script could help accomplish that.

$ for ((COUNT=0; COUNT<1000; COUNT++)); do echo $COUNT; $(cat FILE1GB.dat >> BIGFILE1TB.dat); done

Be sure the file is empty before start, or add code on COUNT=0 to > instead of >>. Many ways.
 
Old 07-26-2019, 06:49 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Wouldn't this too work?
Code:
sudo fallocate -l 1GB dummyfile
http://man7.org/linux/man-pages/man1/fallocate.1.html

which is used for swap files, and is not much different then dd to create the same. Just a crap file that then is assigned to be swap or whatever after being created.
 
  


Reply

Tags
linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Older PCs with 1TB drive want to combine all space bkone Linux - General 16 10-19-2016 03:57 AM
How to create a dummy network interface (and/or bridge) PatrickBaer Linux - Networking 0 01-09-2014 12:44 PM
I want to 'dd' my 1TB drive junior-s Linux - Newbie 29 04-27-2013 07:36 AM
How to create,send,recevice dummy packets using c/java lang. gopal_patil06 Programming 1 03-14-2009 05:28 AM
How to create a dummy printer areku Linux - Software 2 01-25-2006 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration