LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 11: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, 11:41 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,052

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
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 11:46 AM.
 
Old 05-16-2015, 11: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, 02: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, 03:19 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,056

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
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, 04: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, 08: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, 09:01 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,056

Rep: Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915Reputation: 1915
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, 12:02 PM   #9
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,088

Rep: Reputation: 196Reputation: 196
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, 02:32 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,147

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
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, 05: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, 05:17 PM   #12
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,088

Rep: Reputation: 196Reputation: 196
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 02:00 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration