Register now and start sharing your code snippets.
-->

How to unzip, gunzip, untar files with Ruby

Ruby posted 2 months ago by christian

This is a very advanced and resource efficient algorithm for expanding compressed content with Ruby:

   1  def gunzip(filename)
   2    command = "gunzip --force #{filename}"
   3    success = system(command)
   4    
   5    success && $?.exitstatus == 0
   6  end

To customize, change gunzip to whatever command you like.

For example, to avoid 100% CPU utilization during uncompression, set the niceness value of the command with nice -n 5 <command>:

   1  command = "nice -n 5 gunzip --force #{filename}"

There’s also ionice…

Tagged gunzip, ruby, untar, unzip, nice, ionice

Find a text pattern in jar files

Shell Script (Bash) posted about 1 year ago by marko

Helpful when you need to find a class or package in some jar file recursively below the current directory. Still needs a test to see if the file found was a file or directory. Works case insensitively. Uses the unzip command because of it’s performance superiority in comparison to jar.

   1  #!/bin/sh
   2  for f in `find . -type f -name '*\.jar'`
   3  do
   4          unzip -l $f | grep -i $1 && echo "was found in $f"
   5  done

Tagged jar, find, search, recursive, linux, unzip