Menu

p7zip - overwrite destination archive instead of adding content to it?

Help
Rado
2020-06-15
2021-01-01
  • Rado

    Rado - 2020-06-15

    Hi. For some time I noticed that when I'm creating an archive which already exists in the destination, p7zip opens that archive and adds new content to it which makes the archive to grow in size over time and that's not acceptable. I wanna make it overwrite the existing archive with the newly created one - just like WinRAR does in Windows by default.
    For the moment I'm using the remove command to delete the existing target file and another command to create it anew but I was hoping there would be a more... subtle way to do that?

     

    Last edit: Rado 2020-06-15
  • Sam Tansy

    Sam Tansy - 2020-06-19

    Did you try on github? There are fe projects that at least try to develop it. Maybe they will be able to help you.

    In order of recent updates:
    szcnick/p7zip/
    3rdpartyrepos/p7zip/
    develar/7zip-bin
    tehmul/p7zip-zstd/

     
    • Rado

      Rado - 2021-01-01

      I didn't know these existed, I'll check them out. Thanks!

       
  • halo117nachos

    halo117nachos - 2020-12-29

    You could try writing your archive to stdout, and redirecting it to a file. Of course, I say this on the assumption that the archive you're trying to write supports this (the *.7z file format doesn't, AFAIK). I find this particularly useful when crating xz-compressed tar files: tar cf - some_directory | 7za a . -si -so -txz > some_file.tar.xz This will allow you to overwrite files without 7za even knowing that it is overwriting files. Of course, you won't get any "are you sure you want to overwrite this file?" type warnings when you do this, so proceed with caution.

    For the *.7z format (and probably others), you can just delete everything in the archive like so: 7za d some_file.7z "*". This isn't the most graceful solution, but at least it's an option. Just make sure to escape the "*" character: you want it to be interpreted as a wild card by 7za NOT your command shell. PS: 7za d some_file.7z might also work, as I believe 7za will delete all data by default unless the user specifies at least one file/folder to delete. I could be mistaken, however. Also, although this works with *.7z files, it doesn't work with *.xz files, so you'd probably be better off using stdout, as described above.

    These solutions were tested on p7zip 17.03, so if you're using 16.02, you should take this with a slight grain of salt. You can download the newer version here, if you want.

     

    Last edit: halo117nachos 2020-12-29
    • Rado

      Rado - 2021-01-01

      The newer version is available in AUR, I'll download it from there.
      Just 2 questions for clarification though:
      • the asterisk with the quotes comes after the file name, not before?
      • 7za is one word? Not "7z a"?

       

Log in to post a comment.