Windowsではデフォルトでzip
コマンドがインストールされていませんが、Scoop
などのパッケージマネージャーを使用して簡単にインストールできます。
Scoopのインストール
Scoopがまだインストールされていない場合は、PowerShellを開いて以下のコマンドを実行してScoopをインストールします。
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex
zipコマンドのインストール
Scoopをインストールしたら、次にzipコマンドをインストールします。PowerShellで以下のコマンドを実行してください。
scoop install zip
このコマンドにより、zipユーティリティがインストールされます。
zipコマンドの基本的な使い方
zipコマンドを使用してファイルやフォルダーを圧縮する基本的な方法は非常にシンプルです。
zip --help
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f freshen: only changed files -u update: only changed or new files
-d delete entries in zipfile -m move into zipfile (delete OS files)
-r recurse into directories -j junk (don't record) directory names
-0 store only -l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster -9 compress better
-q quiet operation -v verbose operation/print version info
-c add one-line comments -z add zipfile comment
-@ read names from stdin -o make zipfile as old as latest entry
-x exclude the following names -i include only the following names
-F fix zipfile (-FF try harder) -D do not add directory entries
-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
-T test zipfile integrity -X eXclude eXtra file attributes
-! use privileges (if granted) to obtain all aspects of WinNT security
-$ include volume label -S include system and hidden files
-e encrypt -n don't compress these suffixes
-h2 show more help
ファイルの圧縮とパスワード保護
コマンドラインやPowerShellで以下のコマンドを実行して、複数のファイルをパスワード付きで圧縮します。
zip -p yourpassword -e xxx.zip file1 file2
このコマンドでは、-pオプションに続けてパスワードを指定し、-eオプションを使って暗号化(パスワード保護)を有効にしています。xxx.zipは作成されるZIPファイルの名前で、file1とfile2は圧縮したいファイルの名前です。
まとめ
この記事では、Windowsでzipコマンドを使用するための準備と基本的な使用方法について説明しました。Scoopを使ったインストール方法から、ファイルの圧縮とパスワード保護の追加まで、手順を追って説明しました。これで、Windows環境でもzipコマンドを効果的に活用することができます。