LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create large size file with some random characters and numbers? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-large-size-file-with-some-random-characters-and-numbers-4175542774/)

lalitaddiwar 05-16-2015 10:39 AM

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.

schneidz 05-16-2015 10:41 AM

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.

veerain 05-16-2015 10:52 AM

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'.

lalitaddiwar 05-17-2015 01:02 AM

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.

syg00 05-17-2015 02:19 AM

We are not mind readers. Show the command you used and the message(s), and specifications of the file - especially the size.

lalitaddiwar 05-17-2015 03:52 AM

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.

veerain 05-17-2015 07:08 AM

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.

syg00 05-17-2015 08:01 AM

Quote:

Originally Posted by lalitaddiwar (Post 5363502)
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.

arizonagroovejet 05-17-2015 11:02 AM

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?)

rknichols 05-17-2015 01:32 PM

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.

lalitaddiwar 05-17-2015 04:06 PM

@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.

arizonagroovejet 05-18-2015 04:17 PM

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.


All times are GMT -5. The time now is 09:30 AM.