2

I have >200 .zlib Archives and I want to uncompress them using one command in Linux console. I just cant get the command right. maybe somone can help me:

for z in *.zlib; do; zlib-flate -uncompress < $z > $z ; done

When I run this command every file is empty. I don't really care about the output-filename, so this could be just a counter or a added string for example. Many thanks!

  • Why is the in file and outfile the same name? – KevinO Apr 21 '21 at 20:18
  • I hope you have backup of these archives. Or did the syntax error save the day? My point is your command with proper syntax (i.e. without ; after do) empties the files. Don't run it and check the sizes of the files. – Kamil Maciorowski Apr 21 '21 at 20:18
  • @KevinO Like I mentioned: the output-filename does not matter to me, I just need the uncompressed data – jonasbsv Apr 21 '21 at 20:25
  • @KamilMaciorowski Yes I have a backup, don't worry haha. But thanks for the advice. I'm new to bash commands... – jonasbsv Apr 21 '21 at 20:27
  • @KamilMaciorowski Yes I have a backup, don't worry haha. But thanks for the advice. I'm new to bash commands... – jonasbsv Apr 21 '21 at 20:27
  • I think my point, and I believe what @KamilMaciorowski was also suggesting, is that if you attempt to write to the same file that you read, bad things are likely to happen. You might be able to do zlib-flag -uncompress < $z > $z.unc (and remove the ; after the do). The operation should be against actual compressed files with expected sizes, of course. – KevinO Apr 21 '21 at 20:37
  • Thanks! now it's working, but somehow the resulting files are smaller than the original zlib archives. But I think thats another problem and has nothing todo with the command – jonasbsv Apr 21 '21 at 21:02
  • The way the shell works is that command-line redirection (<$z >$z) is handled by the parent shell, before zlib-flate even starts. >%z opens the file for writing, at byte 0. Do all the archives contain the same filenames? Different filenames? – waltinator Apr 21 '21 at 23:37
  • Please [edit] your post to add new information, properly formatted. Information added via comments is hard for you to format, hard for us to read and ignored by future readers. Please click [edit] and add that vital information to your question so all the facts we need are in the question. Please don't use Add Comment, since that's our uplink to you. All facts about your system should go in the Question with [edit] – waltinator Apr 21 '21 at 23:38
  • Read man gzip gunzip. They'd better tools – waltinator Apr 21 '21 at 23:41
  • have you try zlib-flate -uncompress *.zlib? – Romeo Ninov Apr 22 '21 at 06:18

1 Answers1

0

what happened is is the > part executes first and makes a new empty file to collect the output, but this process destroys the intended input data.

To fix: explicitly use a different file-name for the output.

for z in *.zlib; do; zlib-flate -uncompress < "$z" > "${z%.zlib}" ; done

here "${z%.zlib}" trims the .zlib off the end of the filenames.

Jasen
  • 3,761