How to append data in a file by dd?












17














I want to append new data in a file stored in SSD.



dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append


But df -h shows the dd command always overwrite the test file, instead appends new data in the test file.
I also tried



dd if=/dev/shm/test of=/data/sdb/test bs=1G conv=notrunc


It does not work, either.










share|improve this question



























    17














    I want to append new data in a file stored in SSD.



    dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append


    But df -h shows the dd command always overwrite the test file, instead appends new data in the test file.
    I also tried



    dd if=/dev/shm/test of=/data/sdb/test bs=1G conv=notrunc


    It does not work, either.










    share|improve this question

























      17












      17








      17


      5





      I want to append new data in a file stored in SSD.



      dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append


      But df -h shows the dd command always overwrite the test file, instead appends new data in the test file.
      I also tried



      dd if=/dev/shm/test of=/data/sdb/test bs=1G conv=notrunc


      It does not work, either.










      share|improve this question













      I want to append new data in a file stored in SSD.



      dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append


      But df -h shows the dd command always overwrite the test file, instead appends new data in the test file.
      I also tried



      dd if=/dev/shm/test of=/data/sdb/test bs=1G conv=notrunc


      It does not work, either.







      unix ssd dd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 9 '14 at 5:52









      city

      193116




      193116






















          4 Answers
          4






          active

          oldest

          votes


















          10














          What about:



           dd if=/dev/shm/test bs=1G >>/data/sdb/test





          share|improve this answer





















          • your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
            – city
            Dec 9 '14 at 6:46



















          27














          dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 


          That is what I think you should have used.



          REF : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=373736






          share|improve this answer

















          • 1




            Without count=1 option it appends all available space.
            – mixel
            Jan 29 '17 at 17:21



















          1














          In Linux kernel 4.1 FALLOC_FL_INSERT_RANGE option was added. From fallocate(2) man page:




          Specifying the FALLOC_FL_INSERT_RANGE flag (available since Linux 4.1)
          in mode increases the file space by inserting a hole within the file
          size without overwriting any existing data. The hole will start at
          offset and continue for len bytes. When inserting the hole inside
          file, the contents of the file starting at offset will be shifted
          upward (i.e., to a higher file offset) by len bytes. Inserting a hole
          inside a file increases the file size by len bytes.




          And recently this option support was added to util-linux:




             -i, --insert-range
          Insert a hole of length bytes from offset, shifting existing
          data.



          So when util-linux version 2.30 will be released and your linux distro will update to this version we will be able to increase file size in a flash by running:



          fallocate -i -l 1G -o 128M /path/to/file


          where 128M is the current file size.






          share|improve this answer





























            0














            There is an easier way to append a sparse hole to a file.




            truncate is much faster than dd. To grow the file with 10 bytes use:



             truncate -s +10 file.txt 



            answer found in:
            https://serverfault.com/a/343726/70242






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fsuperuser.com%2fquestions%2f850267%2fhow-to-append-data-in-a-file-by-dd%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              10














              What about:



               dd if=/dev/shm/test bs=1G >>/data/sdb/test





              share|improve this answer





















              • your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
                – city
                Dec 9 '14 at 6:46
















              10














              What about:



               dd if=/dev/shm/test bs=1G >>/data/sdb/test





              share|improve this answer





















              • your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
                – city
                Dec 9 '14 at 6:46














              10












              10








              10






              What about:



               dd if=/dev/shm/test bs=1G >>/data/sdb/test





              share|improve this answer












              What about:



               dd if=/dev/shm/test bs=1G >>/data/sdb/test






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 9 '14 at 5:55









              mdpc

              3,81532033




              3,81532033












              • your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
                – city
                Dec 9 '14 at 6:46


















              • your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
                – city
                Dec 9 '14 at 6:46
















              your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
              – city
              Dec 9 '14 at 6:46




              your solution works. Thanks. But do you know why my solutions don't work? I have checked the man page. cannot find the reason. thanks.
              – city
              Dec 9 '14 at 6:46













              27














              dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 


              That is what I think you should have used.



              REF : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=373736






              share|improve this answer

















              • 1




                Without count=1 option it appends all available space.
                – mixel
                Jan 29 '17 at 17:21
















              27














              dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 


              That is what I think you should have used.



              REF : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=373736






              share|improve this answer

















              • 1




                Without count=1 option it appends all available space.
                – mixel
                Jan 29 '17 at 17:21














              27












              27








              27






              dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 


              That is what I think you should have used.



              REF : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=373736






              share|improve this answer












              dd if=/dev/shm/test of=/data/sdb/test bs=1G oflag=append conv=notrunc 


              That is what I think you should have used.



              REF : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=373736







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 9 '14 at 7:16









              Charm_quark

              675514




              675514








              • 1




                Without count=1 option it appends all available space.
                – mixel
                Jan 29 '17 at 17:21














              • 1




                Without count=1 option it appends all available space.
                – mixel
                Jan 29 '17 at 17:21








              1




              1




              Without count=1 option it appends all available space.
              – mixel
              Jan 29 '17 at 17:21




              Without count=1 option it appends all available space.
              – mixel
              Jan 29 '17 at 17:21











              1














              In Linux kernel 4.1 FALLOC_FL_INSERT_RANGE option was added. From fallocate(2) man page:




              Specifying the FALLOC_FL_INSERT_RANGE flag (available since Linux 4.1)
              in mode increases the file space by inserting a hole within the file
              size without overwriting any existing data. The hole will start at
              offset and continue for len bytes. When inserting the hole inside
              file, the contents of the file starting at offset will be shifted
              upward (i.e., to a higher file offset) by len bytes. Inserting a hole
              inside a file increases the file size by len bytes.




              And recently this option support was added to util-linux:




                 -i, --insert-range
              Insert a hole of length bytes from offset, shifting existing
              data.



              So when util-linux version 2.30 will be released and your linux distro will update to this version we will be able to increase file size in a flash by running:



              fallocate -i -l 1G -o 128M /path/to/file


              where 128M is the current file size.






              share|improve this answer


























                1














                In Linux kernel 4.1 FALLOC_FL_INSERT_RANGE option was added. From fallocate(2) man page:




                Specifying the FALLOC_FL_INSERT_RANGE flag (available since Linux 4.1)
                in mode increases the file space by inserting a hole within the file
                size without overwriting any existing data. The hole will start at
                offset and continue for len bytes. When inserting the hole inside
                file, the contents of the file starting at offset will be shifted
                upward (i.e., to a higher file offset) by len bytes. Inserting a hole
                inside a file increases the file size by len bytes.




                And recently this option support was added to util-linux:




                   -i, --insert-range
                Insert a hole of length bytes from offset, shifting existing
                data.



                So when util-linux version 2.30 will be released and your linux distro will update to this version we will be able to increase file size in a flash by running:



                fallocate -i -l 1G -o 128M /path/to/file


                where 128M is the current file size.






                share|improve this answer
























                  1












                  1








                  1






                  In Linux kernel 4.1 FALLOC_FL_INSERT_RANGE option was added. From fallocate(2) man page:




                  Specifying the FALLOC_FL_INSERT_RANGE flag (available since Linux 4.1)
                  in mode increases the file space by inserting a hole within the file
                  size without overwriting any existing data. The hole will start at
                  offset and continue for len bytes. When inserting the hole inside
                  file, the contents of the file starting at offset will be shifted
                  upward (i.e., to a higher file offset) by len bytes. Inserting a hole
                  inside a file increases the file size by len bytes.




                  And recently this option support was added to util-linux:




                     -i, --insert-range
                  Insert a hole of length bytes from offset, shifting existing
                  data.



                  So when util-linux version 2.30 will be released and your linux distro will update to this version we will be able to increase file size in a flash by running:



                  fallocate -i -l 1G -o 128M /path/to/file


                  where 128M is the current file size.






                  share|improve this answer












                  In Linux kernel 4.1 FALLOC_FL_INSERT_RANGE option was added. From fallocate(2) man page:




                  Specifying the FALLOC_FL_INSERT_RANGE flag (available since Linux 4.1)
                  in mode increases the file space by inserting a hole within the file
                  size without overwriting any existing data. The hole will start at
                  offset and continue for len bytes. When inserting the hole inside
                  file, the contents of the file starting at offset will be shifted
                  upward (i.e., to a higher file offset) by len bytes. Inserting a hole
                  inside a file increases the file size by len bytes.




                  And recently this option support was added to util-linux:




                     -i, --insert-range
                  Insert a hole of length bytes from offset, shifting existing
                  data.



                  So when util-linux version 2.30 will be released and your linux distro will update to this version we will be able to increase file size in a flash by running:



                  fallocate -i -l 1G -o 128M /path/to/file


                  where 128M is the current file size.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 29 '17 at 18:15









                  mixel

                  22637




                  22637























                      0














                      There is an easier way to append a sparse hole to a file.




                      truncate is much faster than dd. To grow the file with 10 bytes use:



                       truncate -s +10 file.txt 



                      answer found in:
                      https://serverfault.com/a/343726/70242






                      share|improve this answer


























                        0














                        There is an easier way to append a sparse hole to a file.




                        truncate is much faster than dd. To grow the file with 10 bytes use:



                         truncate -s +10 file.txt 



                        answer found in:
                        https://serverfault.com/a/343726/70242






                        share|improve this answer
























                          0












                          0








                          0






                          There is an easier way to append a sparse hole to a file.




                          truncate is much faster than dd. To grow the file with 10 bytes use:



                           truncate -s +10 file.txt 



                          answer found in:
                          https://serverfault.com/a/343726/70242






                          share|improve this answer












                          There is an easier way to append a sparse hole to a file.




                          truncate is much faster than dd. To grow the file with 10 bytes use:



                           truncate -s +10 file.txt 



                          answer found in:
                          https://serverfault.com/a/343726/70242







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 19 '18 at 19:38









                          akostadinov

                          845918




                          845918






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2fsuperuser.com%2fquestions%2f850267%2fhow-to-append-data-in-a-file-by-dd%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

                              Index of /

                              Tribalistas

                              Listed building