Timeline for How to create a large file in UNIX?
Current License: CC BY-SA 3.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 13, 2016 at 19:05 | comment | added | ElleJay | @terdon It's mostly fs-agnostic and always works. But it's more sane to use it when you really want to copy byte-by-byte Images (isol for example. It's fast if you give proper values for bs= | |
| Mar 13, 2016 at 5:19 | comment | added | Random832 |
The proper non-dd way of doing this specific task would be head -c 1048576 /dev/zero > file
|
|
| Mar 13, 2016 at 5:17 | comment | added | Random832 | @terdon the reason people use dd for disk images is because they've seen it used in tutorials and such and assume there's some reason behind it. The original reason for using it was a bug in an early version of GNU cp (which could otherwise be used) that caused it to screw up in writing all-zero blocks. I've written about this: unix.stackexchange.com/a/189091/6290 | |
| Mar 12, 2016 at 17:48 | comment | added | terdon♦ |
@robertotomás yes, everyone uses dd, but I have never understood why. In fact, I think I've only ever used it to read an MBR or similar fringe tasks. In my experience, other tools are faster, simpler and safer for the vast majority of cases where people use dd. I think this is one of those cases where common != optimal, like sudo su or cat file | grep foo.
|
|
| Mar 12, 2016 at 15:03 | comment | added | roberto tomás |
as you can see in the comment above, and other answers below, it is in fact a common answer. everyone uses dd, and it is an important tool to know if you find yourself doing cli admin tasks. /dev/zero might be relatively slow but you can always use a form like yes|dd of=... if you prefer. answers that do not use dd don't reinforce the memory of essential admin tools. — again, I want to reiterate, and this is visible in my initial comment, I don't think you are wrong, neither in your answers nor in the comment that dd if=/dev/zero can be slow. I was just talking about what is common
|
|
| Mar 12, 2016 at 13:51 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 1 character in body
|
| Mar 12, 2016 at 13:47 | comment | added | Stéphane Chazelas |
@robertotomás, why would it be typical or lazy? It's longer to type than the truncate or fallocate or dd seek=xxx ones, so less lazy in terms of human effort and also a lot less lazy in terms of computer effort.
|
|
| Mar 12, 2016 at 13:22 | comment | added | roberto tomás | hi @StéphaneChazelas , I'm a little confused. Why did you write back to tell me that? The answer you've already written has several inefficient solutions at the top. I actually thought we were in agreement that efficiency doesnt matter for such small "large files". My comment was just pointing out that one of the answers in this discussion is in my opinion the typical lazy solution. | |
| Mar 12, 2016 at 7:10 | comment | added | Stéphane Chazelas |
@robertotomás, again, if it's to create a large file filled with zeroes, see Create a test file with lots of zero bytes linked in the answer, where dd if=/dev/zero is the least efficient.
|
|
| Mar 12, 2016 at 1:50 | comment | added | roberto tomás | I appreciate Stéphane's answers but I think of Doug's as the typical one. | |
| Mar 12, 2016 at 1:06 | comment | added | Stack Exchange Broke The Law | Or use /dev/urandom instead of /dev/zero if you want random data. | |
| Mar 11, 2016 at 19:31 | vote | accept | Thomas Lee | ||
| Mar 11, 2016 at 15:35 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 97 characters in body
|
| Mar 11, 2016 at 15:31 | comment | added | Stéphane Chazelas | @DougO'Neal, see Create a test file with lots of zero bytes | |
| Mar 11, 2016 at 15:27 | comment | added | 123 |
@DougO'Neal I find dd if=/dev/zero of=test bs=1M count=1 to be clearer.
|
|
| Mar 11, 2016 at 15:26 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 |
added 612 characters in body
|
| Mar 11, 2016 at 15:13 | comment | added | doneal24 |
Or dd if=/dev/zero of=large-file bs=1024 count=1024 for a 1MB file
|
|
| Mar 11, 2016 at 15:07 | history | answered | Stéphane Chazelas | CC BY-SA 3.0 |