Friday, April 19, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  40] [ 0]  / answers: 1 / hits: 23813  / 1 Year ago, sun, november 6, 2022, 5:30:36

What is a quick and easy way to make a file that is, say, 2 GB in size?


More From » files

 Answers
5

The zero-fill method (here modified to avoid potential memory bottlenecks) took 17 seconds to create a 10 GB file on an SSD and caused Ubuntu's graphical interface to become unresponsive.



$ time sh -c 'dd if=/dev/zero iflag=count_bytes count=10G bs=1M of=large; sync'
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 17.2003 s, 624 MB/s

real 0m17.642s
user 0m0.008s
sys 0m9.404s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
10737422336 large


fallocate creates large files instantly by directly manipulating the file's allocated disk space:



$ time sh -c 'fallocate -l 10G large; sync'

real 0m0.038s
user 0m0.000s
sys 0m0.016s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
10737422336 large


truncate also works instantly, and creates sparse files which don't use up actual disk space until data is written later on:



$ time sh -c 'truncate -s 10G large; sync'

real 0m0.014s
user 0m0.000s
sys 0m0.004s
$ du -B 1 --apparent-size large
10737418240 large
$ du -B 1 large
0 large

[#44710] Tuesday, November 8, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
odenanno

Total Points: 207
Total Questions: 113
Total Answers: 94

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
odenanno questions
;