3

I have some directories (linux machine) full of highly compressible *.foo files.

Right now I just have a script that does gzip *.foo and it gzips each file into its own .gz file, and removes the original. 7z will compress these files to half the size that gzip will, so I'd like to switch to that.

How can I use 7z to start with a directory like this

file1.foo
file2.foo
file3.foo

and end up with

file1.foo.7z
file2.foo.7z
file3.foo.7z

Or similar. I don't want all of the files in one .7z archive.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
LVLAaron
  • 436
  • 6
  • 13

2 Answers2

3
for i in *.foo; do 7za a $i.7z $i; if [ $? -eq 0 ]; then rm $i; fi; done
dialt0ne
  • 3,065
  • 20
  • 27
0

Give this a try:

find -type f -maxdepth 1 -name "*.foo" -print0 | xargs -0 -I % 7z a %.7z %

but that will leave the original file after it's compressed.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151