![]() Shred is an interesting utility mainly used to overwrite a file repeatedly, in order to make it harder for even very expensive hardware probing to recover the initial data contained by that file.Ĭ) Using /dev/urandom: “head -c file_size/dev/urandom > file_name” $ head -c 10M /dev/urandom > urandom_10M.txt Conclusion Then check the file: $ ls -alh shred_file.txt I will present three ways of generating a 10 MB file containing random data.Ī) Using dd: “dd if=input_file of=output_file bs=block_size count=number of blocks” $ dd if=/dev/urandom of=random_dd.txt bs=10M count=1ġ0485760 bytes (10 MB) copied, 0.107385 s, 97.6 MB/sĪs you can see, additional information is presented – the time it took to write the file ( 0.107385 s ) and the writing speed ( 97.6 MB/s ).ī) Using shred: you first need to create the file and then “shred -n 1 -s 10M file_name” $ touch shred_file.txt & shred -n 1 -s 10M shred_file.txt I know I used it for testing disk write and read speed, but it can also be used in software developing and testing, compression algorithms, and many other scenarios. Sometimes you need to generate a larger block of random data and put it in a file. Obviously, this can be used for password generation. Generate a random complex 15 character string, using ASCII printable characters: $ cat /dev/urandom | tr -dc "" | fold -w 15 |head -n 1 Generate a random 10 character, UPPER CASE and lower case letters, string: $ cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 10 |head -n 1 Generate a random letter: $ cat /dev/urandom | tr -dc 'A-Z' | fold -w 1 |head -n 1 For this part of the tutorial, I will use the special /dev/urandom file. The use cases for random letters and strings are too many to be enumerated here, so I’ll just skip to the technical part. ![]() Use cat to view the content of the file: Generating Random Letters and Strings The above command will write the 6 numbers to a numbers.txt file and it will not show the numbers on the screen. We can do this using a one-liner: $ for((i=1 i” symbol. Let’s say we need to generate 10 random numbers. Doing a simple echo of this variable/function will throw a number: $ echo $RANDOMīut we need more than this, we need to be more specific most of the time. $RANDOM is an internal Bash function that returns a pseudorandom integer in the 0 – 32767 range. Generating Random Numbers Using Variablesįor this part of the tutorial, I will use the $RANDOM variable. ![]() Generating Files Containing Random Data.Generating Random Numbers Using Variables.There are many reasons you need random data, some of them are related to encryption, password creation, lottery numbers, read and write speed tests, etc.īelow is the table of contents of this tutorial: A lot of times, a little hazard is good and also needed in our lives.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |