69

I am using "git bash" on Windows - that is git for Windows via the integrated bash. Apparently it uses the MINGW/MSYS underpinning. (Update from @VonC: It now uses msys2 since msysgit is obsolete since Q4 2015.)

So there are already a lot of MSYS tools installed - from awk to zcat. However I miss the man command and zip to compress multiple files into a zip file (unzip exists!).

Where from can I install them? I do not want to install another copy of the MINGW system! Any way just to add some pre-compiled tools to the git bash installation?

Community
  • 1
  • 1
halloleo
  • 6,554
  • 6
  • 46
  • 88

16 Answers16

43

The zip command can be install from GoW (Gnu On Windows). man is not provided (too big).

It is to note however, that if you only want to add the zip command from GoW, still the whole GoW system has to be downloaded and installed. Then you can delete the other commands from the bin directory, however make sure to keep the needed dlls in the directory.

halloleo
  • 6,554
  • 6
  • 46
  • 88
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks for the clarification about `msys2`. – halloleo Aug 09 '16 at 03:52
  • Not sure about installing GoW - this would replicate most of the already existng comands. So maybe it is better to start again with msys2 itself and then add `git`, `zip` and `man` to it... – halloleo Aug 09 '16 at 03:58
  • You can extract from how only the zip.exe you need. – VonC Aug 09 '16 at 04:12
  • I have a controlled laptop and can't install things into the typical directories. I can put "zip" in my path, but what about the DLLs? – tggagne Feb 01 '17 at 17:28
  • @tggagne you should be able to install GoW wherever you want/can. Or you can uncompress https://osdn.net/dl/peazip/peazip_portable-6.3.0.WIN64.zip again wherever you want and benefit from 7z.exe which can handle zip, rar, tar, ... – VonC Feb 01 '17 at 19:32
28

Adding 7-zip to gitbash is easy.

  1. Install 7-zip on windows.
  2. add 7-zip folder (C:\Program Files\7-Zip) to PATH
    On gitbash exp: export PATH=$PATH:"C:\Program Files\7-Zip" (temporary)
    On Windows, adding PATH like image below (permanent)

enter image description here

  1. duplicate a copy of 7z.exe to be zip.exe
  2. reopen gitbash again. done!

If you skip step 3. you still can call zip command as 7z instead of zip

I have just made it work! on my laptop.

Conclusion: Gitbash is running base on windows Path, I think you can run any command that you have added to your Windows PATH.
By the way, don't forget to give feedback of your result if you try this.

nokieng
  • 1,166
  • 12
  • 18
  • 4
    This worked for me, but didn't find the need for step 3, I used the `7z` command instead. Example: `7z a -r zipped_filename.zip *` – martti d Apr 08 '19 at 03:34
  • @linuxeasy I have never done that before as I remember. – nokieng Aug 05 '19 at 02:10
  • 1
    Thanks @nokieng. Step 3 was what I was looking for my specific need of installing Sdkman on windows. – Dexter Jun 09 '20 at 10:09
  • great.. this was a simple, easy and effective trick that not only worked just fine but saved a lot of time:) Thank you. I was in the same situation and now good to go with the sdkman installation. – itsraghz Aug 26 '20 at 17:09
  • This worked for me saved me having to install zip on gitbash which for some inexplicable reason doesn't have a package manager – SystemsInCode Dec 12 '20 at 14:36
19

Here's another, slightly different, set of instructions install zip for git bash on windows:

  1. Navigate to https://sourceforge.net/projects/gnuwin32/files/zip/3.0/
  2. Download zip-3.0-bin.zip
  3. In the zipped file, in the bin folder, find the file zip.exe.
  4. Extract the file “zip.exe” to your "mingw64" bin folder (for me: C:\Program Files\Git\mingw64\bin)
  5. Navigate to https://sourceforge.net/projects/gnuwin32/files/bzip2/1.0.5/
  6. Download bzip2-1.0.5-bin.zip
  7. In the zipped file, in the bin folder, find the file bzip2.dll
  8. Extract bzip2.dll to your "mingw64" bin folder ( same folder - C:\Program Files\Git\mingw64\bin )
NSjonas
  • 7,200
  • 5
  • 42
  • 78
13

I am so glad to share my experience on this issue that I haven't known for two years since the first day I played with Groovy. My method needs to have git for Windows installed in Windows OS.

These steps are for installing 7z command-line utility, which behaves a bit differently from zip:

  • Download and install 7-Zip from its official website. By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case.
  • Run git Bash under Administrator privilege and navigate to the directory /c/Program Files/Git/mingw64/bin, you can run the command ln -s "/c/Program Files/7-Zip/7z.exe" 7z.exe

I am pretty sure it could help you a lot. Trust me!

Erik Humphrey
  • 294
  • 3
  • 16
Tung
  • 1,245
  • 4
  • 13
  • 32
13

git-archive, is prepared without any installation, can create zip-archive.

mkdir workrepo
cd workrepo
git init
cp -r [target_file_or_dir] .
git add .
git commit -m commit
git archive -o ../myarchive.zip @
cd ..
rm -rf workrepo

Following script may be usable: zip.sh foo.zip target_file_or_dir

#!/usr/bin/bash

set -eu

unset workdir
onexit() {
  if [ -n ${workdir-} ]; then
    rm -rf "$workdir"
  fi
}
trap onexit EXIT

workdir=$(mktemp --tmpdir -d gitzip.XXXXXX)


cp -r "$2" "$workdir"

pushd "$workdir"
git init
git add .
git commit -m "commit for zip"
popd

git archive --format=zip -o "$1" --remote="$workdir" HEAD
  • For `cp` commands: prefer the use of the `-a` option instead of the `-r` option. "Everyone" uses the `-r` option while "everyone" wants the `-a` behavior... – syme Sep 05 '19 at 15:36
6

I use choco as my Windows Package Manager.

I install 7zip with choco using PowerShell (you must be admin to use Choco)

PS > choco install 7zip.install

Open another gitbash Terminal and locate the 7z.exe executable

$ which 7z
/c/ProgramData/chocolatey/bin/7z

Do a straight copy of 7z.exe to zip.exe and voila

$ cp /c/ProgramData/chocolatey/bin/7z.exe /c/ProgramData/chocolatey/bin/zip.exe
setrar
  • 81
  • 1
  • 4
5

You can mimic a small subset of man behavior in the shell by mapping man <command> to <command> --help | less

Unfortunately, on my machine bash aliases won't add flags to positional arguments, it will try to run the flag as a command and fail (alias man="$1 --help" doesn't work).

And a function called man() is not allowed!

Luckily a combination of bash functions and aliases can achieve this mapping. Put the code below in your ~/.bashrc (create one if it is not there). Don't forget to source ~/.bashrc.

# man command workaround: alias can't pass flags, but can't name function man
m() {
    "$1" --help | less
}
alias man="m"

It doesn't get you the full man page, but if all you're looking for is basic info on a command and its flags, this might be all you need.

Dylan Kirkby
  • 1,337
  • 10
  • 18
  • Interesting alternative. +1. Although ` --help` is often a small subset of an actual `man ` content – VonC Aug 09 '17 at 20:55
  • Creative thinking! :-) My question though was not about the `man` tool alone. And I guess the `zip` functionality is harder to emulate with bash functions & aliases. ;-) – halloleo Aug 10 '17 at 03:58
5

You can install individual GNU tools from http://gnuwin32.sourceforge.net/packages.html such as zip.

Then add "/c/Program Files (x86)/GnuWin32/bin" to PATH in your startup script like .profile, .bash_profile, .bashrc, etc.

wisbucky
  • 22,510
  • 8
  • 103
  • 76
4

Here are the steps you can follow.

  1. Go to the following link https://sourceforge.net/projects/gnuwin32/files/

  2. Find out whatever command you are missing Here I need zip and bzip2 for zip command. Because zip command relies on bzip2.dll to run. Otherwise you will get error “error while loading shared libraries: ?: cannot open shared object file: No such file or directory”.

  3. Unzip the downloaded files Here I am downloading “zip-3.0-bin.zip” for “zip.exe” and “bzip2-1.0.5-bin.zip” for “bzip2.dll” in the bin folder. /bin/.exe

  4. Copy the command exe file into git-bash folder Here I am copying “zip.exe” and “bzip2.dll” to \Git\usr\bin.

Reference Link https://ranxing.wordpress.com/2016/12/13/add-zip-into-git-bash-on-windows/

sagecoder
  • 101
  • 5
2

In msys2, I restored the functionality of git help <command> by installing man-db:

|prompt> pacman -Syu man-db
|prompt> git help archive

For zip functionality, I also use git archive (similar to yukihane's answer).

1

Here's yet another 7-Zip option that I didn't notice:

Create a script named zip:

$ vi ~/bin/zip

Reference 7z specifying the add command followed by the args:

#!/bin/bash
/c/Progra~1/7-Zip/7z.exe a "$@"

Finally make it executable

$ chmod ugo+x ~/bin/zip

This helped to make a ytt build script happy.

+ zip ytt-lambda-website.zip main ytt

7-Zip 18.01 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28

Scanning the drive:
2 files, 29035805 bytes (28 MiB)

Creating archive: ytt-lambda-website.zip

Add new data to archive: 2 files, 29035805 bytes (28 MiB)
bvj
  • 2,846
  • 27
  • 26
1

ln -s /mingw64/bin/ziptool.exe /usr/bin/zip

Zartc
  • 100
  • 4
1

Though this question as been answered quite thoroughly in regards to man there is one alternative to zipping that has not been highlighted here yet. @Zartc brought to my attention that there is a zip compression utility built-in: ziptool. In trying to use it however I found out it is no where near a drop-in replacement and you need to specify each individual file and folder. So I dug into the docs and experimented until I had a bash-function that can do all the heavy lifting and can be used very similar to a basic zip -qrf name * compression call:

zipWithZiptool() {
  # Docs: https://libzip.org/documentation/ziptool.html
  targetFilePath="$1"
  shift
  args=() # collect all args in an array so spaces are handled correctly
  while IFS=$'\n\r' read -r line; do
    if [[ -d "$line" ]]; then
      args+=("add_dir" "$line") # Add a single directory by name
    else
      # add_file <pathInZip> <pathToFile> <startIndex> <length>
      args+=("add_file" "$line" "$line" 0 -1)
    fi
  done <<< "$(find "$@")" # call find with every arg to return a recursive list of files and dirs
  ziptool $targetFilePath "${args[@]}" # quotation is important for handling file names with spaces
}

You can then for example zip the contents of the current directory by calling it like this:

zipWithZiptool "my.zip" *
leondepeon
  • 2,757
  • 1
  • 15
  • 11
0

Regarding zip, you can use a following perl script to pack files:

#!/usr/bin/perl
use IO::Compress::Zip qw(:all);
$z = shift;
zip [ @ARGV ] => $z or die "Cannot create zip file: $ZipError\n";

If you make it executable, name it zip, and put it in your $PATH, you can run it like this:

zip archive.zip files...

however it will not work for directories. There is no need to install anything, as perl and all required modules are already there in the Git for Windows installation.

Regarding man, at least for git there is a documentation invoked like this:

git option --help

it will open in your default browser.

mik
  • 2,677
  • 2
  • 17
  • 27
0

If you are willing to install CygWin also, you can add the CygWin path to your GitBash path, and if zip is there, it will work. e.g. add

PATH=$PATH:/c/cygwin/bin
export PATH

to your .bashrc; NOTE: I would put it at the end of the path as shown, not the beginning.

Since CygWin has a UI-based installer, it's easy to add or remove applications like zip or man.

You can figure out the windows paths of each by saying

`cygpath -w /bin`

in each respective shell.

  • Well, the whole reason why I went down the GitBash/MSYS path was to avoid the installer driven approach of Cygwin. - If I could install Cygwin via zip files or similar (**staying away from in-installer downloads**) this were my first choice! – halloleo Mar 02 '19 at 02:29
  • Let me guess... With Linux, you run Slackware :^) – miles zarathustra Mar 03 '19 at 07:46
0

Here is my experience, I cant run and exe or .msi files in my laptop. so downloaded filed from https://github.com/bmatzelle/gow/wiki > go to download Now and Downloaded Source Code (Zip) and unzipped this file in a folder and updated path variable with folder name. This worked out for me.

Ravi G
  • 11
  • 2