Creating Junk File in Unix

How to create Junk file in Unix

Generally Junk files are created for testing the application developed and so on. Here I have show four methods to create Junk files in Unix:

Method 1: using dd
 
dd if=/dev/zero of=filename.txt count=1024 bs=1024

bs--> Block Size. [1024 *1024 = 1MB file will be created] (or)
dd if=/dev/zero of=filename.txt count=1M bs=1024

 (1MB *1024=1GB file will be created)

dd essentially copy that force to write every block of data (data will be unreadable but return 0)

Method 2: using truncate

truncate –S 10G file.txt

It create a “sparse file” that cheats the file system and says that its has 10GB of data ,in other words it create a virtual data.This is fastest method for creating junk file.

Method 3: using fallocate 

fallocate –L 10 G file.txt

It will allocate a 10 GB in memory in disk (not sparse file) but we will not have to worry about the data, which means anything could be there.

Method 4: using yes

Yes “some text” | head –n 100000 > file.txt

Actually creating a large text file with readable data size of or no of character in “some text” * 100000 will be the file size


Note:
if the required space is not available then the file will be created for the available size
For eg. System has 8GB free space and fallocate -L 10G file.txt made the file.txt will be created for 8GB

Comments