LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-16-2015, 10:39 AM   #1
lalitaddiwar
LQ Newbie
 
Registered: Apr 2015
Posts: 7

Rep: Reputation: Disabled
How to create large size file with some random characters and numbers?


Can anybody tell me how to create large size file in linux? I am using truncate but it is not creating files with some random characters ad numbers.
Please suggest me commands with syntax and example to create large size file with some random characters and numbers in linux with proper explanation.
Thank You.
 
Old 05-16-2015, 10:41 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
man truncate
TRUNCATE(1)                                           User Commands                                           TRUNCATE(1)

NAME
       truncate - shrink or extend the size of a file to the specified size
...
now theres your problem.

if you are looking for random readable text, i would echo $RANDOM into a file within a while loop.
if you are looking for random binary data, i would cat /dev/random (or /dev/urandom) into a file.

Last edited by schneidz; 05-16-2015 at 10:46 AM.
 
Old 05-16-2015, 10:52 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Run:

Code:
dd if=/dev/urandom of=file1 bs=1M count=1
Replace 'M' with required unit and put how much counts you want of that bs data.
For more info read manpage of 'dd'.
 
1 members found this post helpful.
Old 05-17-2015, 01:02 AM   #4
lalitaddiwar
LQ Newbie
 
Registered: Apr 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
I am new but when I am running dd command for creating large file then at the end it is showing error. Whether it is possible to suggest new command.
 
Old 05-17-2015, 02:19 AM   #5
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
We are not mind readers. Show the command you used and the message(s), and specifications of the file - especially the size.
 
Old 05-17-2015, 03:52 AM   #6
lalitaddiwar
LQ Newbie
 
Registered: Apr 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
Ok,
Here is my command used

$ dd if=/dev/urandom of=file.txt bs=100M count=10
But it is showing error when i am opening this file.txt using the command

$ cat file.txt

The error is 62;9;c62;9;62;9 command not found
62; command not found
9; command not found

These are more replicative when i am increasing the count value.

So is there any other command to create long file with random data.
 
Old 05-17-2015, 07:08 AM   #7
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Never run a 'cat' command on a binary or a random file. Use cat to only output text files. Because if the file content happens to be terminal command it would make errors.

Instead use vim editor or use hexdump command to view the random bytes filled file.
 
Old 05-17-2015, 08:01 AM   #8
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
Quote:
Originally Posted by lalitaddiwar View Post
when I am running dd command for creating large file then at the end it is showing error.
It has nothing to do with the dd command creating the file.
If you want help, describe your situation correctly.
 
1 members found this post helpful.
Old 05-17-2015, 11:02 AM   #9
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
The problem I see in this thread is that it's not clear what you want. It's especially not clear because what I think you probably want based upon your first post is not what you have subsequently tried to generate.


Your original post says "large size file with some random characters and numbers". Some people may consider a number to be a character which would make your specification of numbers redundant.


I would guess you're looking for a file that contains something like
Code:
k'povjyhk 'onu*y'y*Y*@%6nb4u;obu@*^@y4'@u@oI@POU^'9u49N@(y54'8y@VVY@£8yB4'Y'm'mopi'Ejoi'hgo'\smhoh'OHdohedo'hOI@HDFoDH@M C'u*$£@coiOINnhoiNY;oby;oby;oiYHouyhouyn 8y979^uighkjg86t*gn y *(ny(Pnt789Tb&* yy'89'Y'8ny&*(
That's the result of my randomly hitting the keyboard whilst trying to hold down a shift key some of the time. one way to generate a lot of that would be to use one of the methods you can easily find only for generating random passwords. Do it in a loop until you have what you consider to be sufficient data.


The first reply you got suggested two methods, one of which would result in a bunch of pseudo random numbers and the second, using dd, which would generate binary data I suspect you don't want binary data. You have chosen the dd command and now you seem to be complaining that it hasn't produced what you want.

I suggest that you post an example of the sort of content you're trying to get and also explain what you mean by 'large file'. (Are you thinking in terms of KB or MB or GB, or hundreds of characters or thousands of characters or tends of thousands of characters, or what?)
 
Old 05-17-2015, 01:32 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,777

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Another way would be to take random binary data and filter out all except the printing ASCII characters:
Code:
dd if=/dev/urandom count=1 | tr -c -d '0-9A-Za-z'     # just letters and digits
dd if=/dev/urandom count=1 | tr -c -d '!-~'           # all of the printing characters
As @arizonagroovejet mentioned, the amount of needed output is important. You will find /dev/urandom quite slow if you need hundreds of megabytes or more.
 
1 members found this post helpful.
Old 05-17-2015, 04:06 PM   #11
lalitaddiwar
LQ Newbie
 
Registered: Apr 2015
Posts: 7

Original Poster
Rep: Reputation: Disabled
@arizonagroovejet
Yes sir i need such file content. Well I am doing project at TU Dresden which splits data of file to different nodes. I need to analyze the code provided by them. For that I need different size files like 1MB 10 MB 1 GB100 MB 10 GB 100 GB files. So I need help so that i can generate such files with some random characters like you mentioned above. Are there any commands to do so easily in linux.
Also I have posted the code in my first post regarding my project.
It will be thankful if you provide me good proper commands to generate such files.
 
Old 05-18-2015, 04:17 PM   #12
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Exactly 1MB, 10MB etc or will approximately do?

Does it matter if there are line breaks in the files?

Did you even look at rknichols suggestions?



I put "linux generate n random characters" in to Google and second hit is this
http://linuxconfig.org/create-a-rand...ng-linux-shell


You'll have to do some experimentation yourself, only you know exactly what you want.
 
1 members found this post helpful.
  


Reply



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
Editing File Shows Random Characters JKF22 Linux - Newbie 3 11-28-2014 07:54 AM
[SOLVED] Random numbers aren't the size I want them errigour Programming 3 09-20-2013 11:56 PM
[SOLVED] sed - replacing random numbers followed with space and more random chars gluposti Linux - Newbie 7 05-07-2012 07:36 PM
using /dev/random to output random numbers on a text file guguma Programming 4 04-02-2007 01:42 PM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 12:12 PM

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

All times are GMT -5. The time now is 08:55 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