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;
}







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?










share|improve this question





























    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?










    share|improve this question

























      0












      0








      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?










      share|improve this question














      $ 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 19 mins ago









      GypsyCosmonautGypsyCosmonaut

      90211435




      90211435






















          1 Answer
          1






          active

          oldest

          votes


















          1















          1. du does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical ( 264084 * 1024 = 270422016 )


          2. truncate creates a sparse file provided the filesystem supports such things


          3. /dev/zero actually produces infinite bytes 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.







          share|improve this answer
























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1















            1. du does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical ( 264084 * 1024 = 270422016 )


            2. truncate creates a sparse file provided the filesystem supports such things


            3. /dev/zero actually produces infinite bytes 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.







            share|improve this answer




























              1















              1. du does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical ( 264084 * 1024 = 270422016 )


              2. truncate creates a sparse file provided the filesystem supports such things


              3. /dev/zero actually produces infinite bytes 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.







              share|improve this answer


























                1












                1








                1








                1. du does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical ( 264084 * 1024 = 270422016 )


                2. truncate creates a sparse file provided the filesystem supports such things


                3. /dev/zero actually produces infinite bytes 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.







                share|improve this answer














                1. du does not show size in bytes, but 1024-byte-blocks. So the numbers are actually identical ( 264084 * 1024 = 270422016 )


                2. truncate creates a sparse file provided the filesystem supports such things


                3. /dev/zero actually produces infinite bytes 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.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 10 mins ago









                frostschutzfrostschutz

                28.1k25892




                28.1k25892






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...