Difference between writing file from /dev/zero and truncateWriting /dev/random to file?Difference between...
When a land becomes a creature, is it untapped?
Can a tourist shoot a gun in the USA?
Can the sorting of a list be verified without comparing neighbors?
Anatomically Correct Carnivorous Tree
How to slow yourself down (for playing nice with others)
Word for being out at night during curfew
Light Switch Terminals
As programers say: Strive to be lazy
Why is “Ich wusste, dass aus dir mal was wird” grammitally correct?
What food production methods would allow a metropolis like New York to become self sufficient
A cryptic tricolour
Extracting sublists that contain similar elements
How are one-time password generators like Google Authenticator different from having two passwords?
Is it a bad idea to replace pull-up resistors with hard pull-ups?
Why is this int array not passed as an object vararg array?
What is the relation between semi-supervised self-supervised visual representation learning?
What are the implications of the new alleged key recovery attack preprint on SIMON?
How does Howard Stark know this?
Definition of Newton's first law
Early arrival in Australia, early hotel check in not available
On studying Computer Science vs. Software Engineering to become a proficient coder
What are the components of a legend (in the sense of a tale, not a figure legend)?
Create a list of all possible Boolean configurations of three constraints
Why not just directly invest in the holdings of an ETF?
Difference between writing file from /dev/zero and truncate
Writing /dev/random to file?Difference between Device file and device driversDifference between /dev and /sys/class?difference between df -h and dfcWhat is the difference between /dev/sda and /dev/hda?Difference between /dev and /sysDifference between /dev/null and /dev/zerodifference between output of df and blkidWhat is the difference between `/dev/input/event*` and `/dev/input/mouse*` according to mouses?Why does GNU Core Utilities stat (including du and ls) report the following sizes (ext4 in GNU/Linux)?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$ timeout 1 cat /dev/zero > file1
$ wc -c file1
270422016 file1
$ du file1
264084 file1
Questions :
(1) How do 270422016 null characters come out to be 264084 bytes (i.e 258M).
$ truncate -s 270422016 file2
$ wc -c file2
270422016 file2
$ du file2
0 file2
Questions :
(2) file2
has been created with same number of null characters as file1
has, but the size of file2
is zero, why?
(3) What did /dev/zero
do that truncate
didn't or vice versa?
disk-usage devices truncate
add a comment |
$ timeout 1 cat /dev/zero > file1
$ wc -c file1
270422016 file1
$ du file1
264084 file1
Questions :
(1) How do 270422016 null characters come out to be 264084 bytes (i.e 258M).
$ truncate -s 270422016 file2
$ wc -c file2
270422016 file2
$ du file2
0 file2
Questions :
(2) file2
has been created with same number of null characters as file1
has, but the size of file2
is zero, why?
(3) What did /dev/zero
do that truncate
didn't or vice versa?
disk-usage devices truncate
add a comment |
$ timeout 1 cat /dev/zero > file1
$ wc -c file1
270422016 file1
$ du file1
264084 file1
Questions :
(1) How do 270422016 null characters come out to be 264084 bytes (i.e 258M).
$ truncate -s 270422016 file2
$ wc -c file2
270422016 file2
$ du file2
0 file2
Questions :
(2) file2
has been created with same number of null characters as file1
has, but the size of file2
is zero, why?
(3) What did /dev/zero
do that truncate
didn't or vice versa?
disk-usage devices truncate
$ timeout 1 cat /dev/zero > file1
$ wc -c file1
270422016 file1
$ du file1
264084 file1
Questions :
(1) How do 270422016 null characters come out to be 264084 bytes (i.e 258M).
$ truncate -s 270422016 file2
$ wc -c file2
270422016 file2
$ du file2
0 file2
Questions :
(2) file2
has been created with same number of null characters as file1
has, but the size of file2
is zero, why?
(3) What did /dev/zero
do that truncate
didn't or vice versa?
disk-usage devices truncate
disk-usage devices truncate
asked 19 mins ago
GypsyCosmonautGypsyCosmonaut
90211435
90211435
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
du
does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical (264084 * 1024 = 270422016
)truncate
creates a sparse file provided the filesystem supports such things/dev/zero
actually produces infinitebytes which are then written to file, and writing zeroes consumes space like writing any other content. Another way of producing a similar file without writing zeroes would be using
fallocate
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518488%2fdifference-between-writing-file-from-dev-zero-and-truncate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
du
does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical (264084 * 1024 = 270422016
)truncate
creates a sparse file provided the filesystem supports such things/dev/zero
actually produces infinitebytes which are then written to file, and writing zeroes consumes space like writing any other content. Another way of producing a similar file without writing zeroes would be using
fallocate
.
add a comment |
du
does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical (264084 * 1024 = 270422016
)truncate
creates a sparse file provided the filesystem supports such things/dev/zero
actually produces infinitebytes which are then written to file, and writing zeroes consumes space like writing any other content. Another way of producing a similar file without writing zeroes would be using
fallocate
.
add a comment |
du
does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical (264084 * 1024 = 270422016
)truncate
creates a sparse file provided the filesystem supports such things/dev/zero
actually produces infinitebytes which are then written to file, and writing zeroes consumes space like writing any other content. Another way of producing a similar file without writing zeroes would be using
fallocate
.
du
does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical (264084 * 1024 = 270422016
)truncate
creates a sparse file provided the filesystem supports such things/dev/zero
actually produces infinitebytes which are then written to file, and writing zeroes consumes space like writing any other content. Another way of producing a similar file without writing zeroes would be using
fallocate
.
answered 10 mins ago
frostschutzfrostschutz
28.1k25892
28.1k25892
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518488%2fdifference-between-writing-file-from-dev-zero-and-truncate%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown