Create a file of a specific size with random printable strings in bash

后端 未结 6 850
陌清茗
陌清茗 2021-01-13 22:27

I want to create a file of a specific size containing only printable strings in bash.

My first thought was to use /dev/urandom:

dd if=/d         


        
6条回答
  •  情书的邮戳
    2021-01-13 22:38

    You can use one of the following:

    1. truncate You should have a baseline textfile with a size larger than what you need. then use the following:

      truncate -s 5M filename
      DESCRIPTION
         Shrink or extend the size of each FILE to the specified size
      
      [...]
      
       -s, --size=SIZE
            set or adjust the file size by SIZE
      

    2.Use tail: this options requires reference text file too.

    tail -c 1MB reference_big.txt> 1mb.txt
    

提交回复
热议问题