Compress all files in a directory separately via command line

How to do this fast and easily? I don’t care about what type of compression was used.

When I say compress I am referring to using a tool such as ZIP to make a file smaller. Separately – that is each file will have its own zipped file, instead of all being bundled into one big one.

ANSWER

On a Linux shell, such as Bash, I can do this command to zip up all the files in a directory individually.

find . -type f -exec zip -D '{}.zip' '{}' \;

The find command allows for finding many things. Here we specify where to look for it through that dot right after the command. Dot means the current directory location. Then the -type f tells it to find only those considered as regular files. Followed by the -exec zip so that when it finds those files it will do a zip on each one. The curly brackets is so that filenames are retained, then appended with a .zip file extension at the end.

Find is recursive. So it will also go down to subdirectories and zip any files in there, and so on. It can be prevented. One way is to use -maxdepth option. If I want it to not recurse deeper I tell it to have a max depth of 1.

find . -maxdepth 1 -type f -exec zip -D '{}.zip' '{}' \;

There are other ways – such as using a for loop on bash – but I’ve always been more comfortable with doing this through the find command.

Then there is also the gzip compression tool. This is another one similar to zip. Gzip command is much simpler and shorter.

gzip *

The * is a wildcard that matches any of the files that are in that current directory. It will ignore directories, so any files in subdirectories will not get compressed. Note that this short command deletes the original file once it’s been compressed. If I want to keep these files, I would put the -k option (long form is --keep).

gzip -k *

These commands will work on perhaps majority of Linux distros, assuming the zip and gzip applications are installed. It will also work on Bash-like shells for Windows. Better yet, Windows 10 has the Windows Subsystem for Linux feature.

How to download a zipfile from a Github repository

I’m trying to download a zipfile from a Github repository with this command:

wget --no-check-certificate https://github.com/brendenlake/omniglot/blob/master/python/images_evaluation.zip -O /tmp/images_evaluation.zip

But it doesn’t download a valid zip file. I suppose that it downloads the HTML file that the browser shows if you click on the url.

How can I download a zip file from a public Github repository using wget?

Go to Source
Author: VansFannel