How to overwrite a file with shell script without using extra device space?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm trying to overwrite a file using:



cp source.txt target.txt



But I get "No space left on device".



I also tried using dd with no success, even with super user.



How can I overwrite using only the space used by the target file?










share|improve this question





















  • Is source larger than target?
    – Jeff Schaller
    Aug 30 at 23:46










  • Did you use dd … >  or dd … of=?
    – G-Man
    Aug 31 at 0:02










  • What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
    – ilkkachu
    Sep 1 at 19:44















up vote
0
down vote

favorite












I'm trying to overwrite a file using:



cp source.txt target.txt



But I get "No space left on device".



I also tried using dd with no success, even with super user.



How can I overwrite using only the space used by the target file?










share|improve this question





















  • Is source larger than target?
    – Jeff Schaller
    Aug 30 at 23:46










  • Did you use dd … >  or dd … of=?
    – G-Man
    Aug 31 at 0:02










  • What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
    – ilkkachu
    Sep 1 at 19:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to overwrite a file using:



cp source.txt target.txt



But I get "No space left on device".



I also tried using dd with no success, even with super user.



How can I overwrite using only the space used by the target file?










share|improve this question













I'm trying to overwrite a file using:



cp source.txt target.txt



But I get "No space left on device".



I also tried using dd with no success, even with super user.



How can I overwrite using only the space used by the target file?







shell-script file-copy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 30 at 23:12









DeniseJF

1




1











  • Is source larger than target?
    – Jeff Schaller
    Aug 30 at 23:46










  • Did you use dd … >  or dd … of=?
    – G-Man
    Aug 31 at 0:02










  • What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
    – ilkkachu
    Sep 1 at 19:44

















  • Is source larger than target?
    – Jeff Schaller
    Aug 30 at 23:46










  • Did you use dd … >  or dd … of=?
    – G-Man
    Aug 31 at 0:02










  • What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
    – ilkkachu
    Sep 1 at 19:44
















Is source larger than target?
– Jeff Schaller
Aug 30 at 23:46




Is source larger than target?
– Jeff Schaller
Aug 30 at 23:46












Did you use dd … >  or dd … of=?
– G-Man
Aug 31 at 0:02




Did you use dd … >  or dd … of=?
– G-Man
Aug 31 at 0:02












What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
– ilkkachu
Sep 1 at 19:44





What operating system is this? What filesystem? The reasons for getting that issue may very well depend on those.
– ilkkachu
Sep 1 at 19:44











1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you have it installed:



$ truncate -s 0 target.txt


Will reduce the file size to zero.



And, maybe:



$ : > target.txt


But perhaps it is a problem with the journal being unable to write to disk. In that case, you need to log in as root to remove some files.






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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f465872%2fhow-to-overwrite-a-file-with-shell-script-without-using-extra-device-space%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you have it installed:



    $ truncate -s 0 target.txt


    Will reduce the file size to zero.



    And, maybe:



    $ : > target.txt


    But perhaps it is a problem with the journal being unable to write to disk. In that case, you need to log in as root to remove some files.






    share|improve this answer


























      up vote
      0
      down vote













      If you have it installed:



      $ truncate -s 0 target.txt


      Will reduce the file size to zero.



      And, maybe:



      $ : > target.txt


      But perhaps it is a problem with the journal being unable to write to disk. In that case, you need to log in as root to remove some files.






      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        If you have it installed:



        $ truncate -s 0 target.txt


        Will reduce the file size to zero.



        And, maybe:



        $ : > target.txt


        But perhaps it is a problem with the journal being unable to write to disk. In that case, you need to log in as root to remove some files.






        share|improve this answer














        If you have it installed:



        $ truncate -s 0 target.txt


        Will reduce the file size to zero.



        And, maybe:



        $ : > target.txt


        But perhaps it is a problem with the journal being unable to write to disk. In that case, you need to log in as root to remove some files.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 1 at 19:26

























        answered Aug 31 at 0:35









        Isaac

        7,18111035




        7,18111035



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465872%2fhow-to-overwrite-a-file-with-shell-script-without-using-extra-device-space%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)