状態:-  閲覧数:2,670  投稿日:2019-08-13  更新日:2019-08-13
$ man zip / $ zip -h / $ zip -h2

絶対パスで圧縮実行 / 相対パスで圧縮実行 / 一つ上の階層を相対パスで指定して、圧縮実行

階層構造で圧縮しないためには? / -o オプション / 未解決

$ man zip / $ zip -h / $ zip -h2

 閲覧数:217 投稿日:2019-08-13 更新日:2019-08-13 

$ man zip

$ man zip
ZIP(1L)                                                                                                                                           ZIP(1L)

      zip - package and compress (archive) files

      zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [--longoption ...]  [-b path] [-n suffixes] [-t date] [-tt date] [zipfile [file ...]]  [-xi list]

      zipcloak (see separate man page)

      zipnote (see separate man page)

      zipsplit (see separate man page)

      Note:   Command  line processing in zip has been changed to support long options and handle all options and arguments more consistently.  Some old
      command lines that depend on command line inconsistencies may no longer work.

      zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows 9x/NT/XP, Minix, Atari, Macintosh, Amiga, and Acorn  RISC  OS.
      It is analogous to a combination of the Unix commands tar(1) and compress(1) and is compatible with PKZIP (Phil Katz's ZIP for MSDOS systems).

      A  companion  program  (unzip(1L)) unpacks zip archives.  The zip and unzip(1L) programs can work with archives produced by PKZIP (supporting most
      PKZIP features up to PKZIP version 4.6), and PKZIP and PKUNZIP can work with archives produced by zip (with some exceptions, notably streamed  ar‐
      chives,  but recent changes in the zip file standard may facilitate better compatibility).  zip version 3.0 is compatible with PKZIP 2.04 and also
      supports the Zip64 extensions of PKZIP 4.5 which allow archives as well as files to exceed the previous 2 GB limit (4 GB in some cases).  zip also
      now  supports  bzip2  compression  if the bzip2 library is included when zip is compiled.  Note that PKUNZIP 1.10 cannot extract files produced by
      PKZIP 2.04 or zip 3.0. You must use PKUNZIP 2.04g or unzip 5.0p1 (or later versions) to extract them.

      See the EXAMPLES section at the bottom of this page for examples of some typical uses of zip.

      Large Archives and Zip64.  zip automatically uses the Zip64 extensions when files larger than 4 GB are added to an archive, an archive  containing
      Zip64  entries is updated (if the resulting archive still needs Zip64), the size of the archive will exceed 4 GB, or when the number of entries in
      the archive will exceed about 64K.  Zip64 is also used for archives streamed from standard input as the size of such archives  are  not  known  in
      advance,  but  the  option  -fz- can be used to force zip to create PKZIP 2 compatible archives (as long as Zip64 extensions are not needed).  You
      must use a PKZIP 4.5 compatible unzip, such as unzip 6.0 or later, to extract files using the Zip64 extensions.

      In addition, streamed archives, entries encrypted with standard encryption, or split archives created with the pause option may not be  compatible
      with  PKZIP as data descriptors are used and PKZIP at the time of this writing does not support data descriptors (but recent changes in the PKWare
      published zip standard now include some support for the data descriptor format zip uses).

      Mac OS X.  Though previous Mac versions had their own zip port, zip supports Mac OS X as part of the Unix port and most Unix features apply.  Ref‐
      erences  to  "MacOS" below generally refer to MacOS versions older than OS X.  Support for some Mac OS features in the Unix Mac OS X port, such as
      resource forks, is expected in the next zip release.

      For a brief help on zip and unzip, run each without specifying any parameters on the command line.

      The program is useful for packaging a set of files for distribution; for archiving files; and for saving disk  space  by  temporarily  compressing
      unused files or directories.

      The  zip  program  puts  one or more compressed files into a single zip archive, along with information about the files (name, path, date, time of
      last modification, protection, and check information to verify file integrity).  An entire directory structure can be packed into  a  zip  archive
      with a single command.  Compression ratios of 2:1 to 3:1 are common for text files.  zip has one compression method (deflation) and can also store
      files without compression.  (If bzip2 support is added, zip can also compress using bzip2 compression, but such entries require a reasonably  mod‐
      ern  unzip to decompress.  When bzip2 compression is selected, it replaces deflation as the default method.)  zip automatically chooses the better
      of the two (deflation or store or, if bzip2 is selected, bzip2 or store) for each file to be compressed.
Manual page zip(1) line 1 (press h for help or q to quit)

$ zip -h

$ zip -h
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
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
 -y   store symbolic links as the link instead of the referenced file
 -e   encrypt                      -n   don't compress these suffixes
 -h2  show more help

$ zip -h2

$ zip -h2
Extended Help for Zip

See the Zip Manual for more detailed help

Zip stores files in zip archives. The default action is to add or replace
zipfile entries.

Basic command line:
zip options archive_name file file ...

Some examples:
Add file.txt to (create z if needed): zip z file.txt
Zip all files in current dir: zip z *
Zip files in current dir and subdirs also: zip -r z .

Basic modes:
External modes (selects files from file system):
add - add new files/update existing files in archive (default)
-u update - add new files/update existing files only if later date
-f freshen - update existing files only (no files added)
-FS filesync - update if date or size changed, delete if no OS match
Internal modes (selects entries in archive):
-d delete - delete files from archive (see below)
-U copy - select files in archive to copy (use with --out)

Basic options:
-r recurse into directories (see Recursion below)
-m after archive created, delete original files (move into archive)
-j junk directory names (store just file names)
-q quiet operation
-v verbose operation (just "zip -v" shows version information)
-c prompt for one-line comment for each entry
-z prompt for comment for archive (end with just "." line or EOF)
-@ read names to zip from stdin (one path per line)
-o make zipfile as old as latest entry

The full command line syntax is:

zip [-shortopts ...] [--longopt ...] [zipfile [path path ...]] [-xi list]

Any number of short option and long option arguments are allowed
(within limits) as well as any number of path arguments for files
to zip up. If zipfile exists, the archive is read in. If zipfile
is "-", stream to stdout. If any path is "-", zip stdin.

Options and Values:
For short options that take values, use -ovalue or -o value or -o=value
For long option values, use either --longoption=value or --longoption value
For example:
zip -ds 10 --temp-dir=path zipfile path1 path2 --exclude pattern pattern
Avoid -ovalue (no space between) to avoid confusion
In particular, be aware of 2-character options. For example:
-d -s is (delete, split size) while -ds is (dot size)
Usually better to break short options across multiple arguments by function
zip -r -dbdcds 10m -lilalf logfile archive input_directory -ll

All args after just "--" arg are read verbatim as paths and not options.
zip zipfile path path ... -- verbatimpath verbatimpath ...
Use -nw to also disable wildcards, so paths are read literally:
zip zipfile -nw -- "-leadingdashpath" "a[path].c" "path*withwildcard"
You may still have to escape or quote arguments to avoid shell expansion

Internally zip supports the following wildcards:
? (or % or #, depending on OS) matches any single character
* matches any number of characters, including zero
[list] matches char in list (regex), can do range [ac-f], all but [!bf]
If port supports [], must escape [ as [[] or use -nw to turn off wildcards
For shells that expand wildcards, escape (\* or "*") so zip can recurse
zip zipfile -r . -i "*.h"

Normally * crosses dir bounds in path, e.g. 'a*b' can match 'ac/db'. If
-ws option used, * does not cross dir bounds but ** does

For DOS and Windows, [list] is now disabled unless the new option
-RE enable [list] (regular expression) matching
is used to avoid problems with file paths containing "[" and "]":
zip files_ending_with_number -RE foo[0-9].c

Include and Exclude:
-i pattern pattern ... include files that match a pattern
-x pattern pattern ... exclude files that match a pattern
Patterns are paths with optional wildcards and match paths as stored in
archive. Exclude and include lists end at next option, @, or end of line.
zip -x pattern pattern @ zipfile path path ...

Case matching:
On most OS the case of patterns must match the case in the archive, unless
the -ic option is used.
-ic ignore case of archive entries
This option not available on case-sensitive file systems. On others, case
ignored when matching files on file system but matching against archive
entries remains case sensitive for modes -f (freshen), -U (archive copy),
and -d (delete) because archive paths are always case sensitive. With
-ic, all matching ignores case, but it's then possible multiple archive
entries that differ only in case will match.

End Of Line Translation (text files only):
-l change CR or LF (depending on OS) line end to CR LF (Unix->Win)
-ll change CR LF to CR or LF (depending on OS) line end (Win->Unix)
If first buffer read from file contains binary the translation is skipped

-r recurse paths, include files in subdirs: zip -r a path path ...
-R recurse current dir and match patterns: zip -R a ptn ptn ...
Use -i and -x with either to include or exclude paths
Path root in archive starts at current dir, so if /a/b/c/file and
current dir is /a/b, 'zip -r archive .' puts c/file in archive

Date filtering:
-t date exclude before (include files modified on this date and later)
-tt date include before (include files modified before date)
Can use both at same time to set a date range
Dates are mmddyyyy or yyyy-mm-dd

Deletion, File Sync:
-d delete files
Delete archive entries matching internal archive paths in list
zip archive -d pattern pattern ...
Can use -t and -tt to select files in archive, but NOT -x or -i, so
zip archive -d "*" -t 2005-12-27
deletes all files from with date of 27 Dec 2005 and later
Note the * (escape as "*" on Unix) to select all files in archive

-FS file sync
Similar to update, but files updated if date or size of entry does not
match file on OS. Also deletes entry from archive if no matching file
on OS.
zip archive_to_update -FS -r dir_used_before
Result generally same as creating new archive, but unchanged entries
are copied instead of being read and compressed so can be faster.
WARNING: -FS deletes entries so make backup copy of archive first

-0 store files (no compression)
-1 to -9 compress fastest to compress best (default is 6)
-Z cm set compression method to cm:
store - store without compression, same as option -0
deflate - original zip deflate, same as -1 to -9 (default)
if bzip2 is enabled:
bzip2 - use bzip2 compression (need modern unzip)

-e use standard (weak) PKZip 2.0 encryption, prompt for password
-P pswd use standard encryption, password is pswd

Splits (archives created as a set of split files):
-s ssize create split archive with splits of size ssize, where ssize nm
n number and m multiplier (kmgt, default m), 100k -> 100 kB
-sp pause after each split closed to allow changing disks
WARNING: Archives created with -sp use data descriptors and should
work with most unzips but may not work with some
-sb ring bell when pause
-sv be verbose about creating splits
Split archives CANNOT be updated, but see --out and Copy Mode below

Using --out (output to new archive):
--out oa output to new archive oa
Instead of updating input archive, create new output archive oa.
Result is same as without --out but in new archive. Input archive
WARNING: --out ALWAYS overwrites any existing output file
For example, to create new_archive like old_archive but add newfile1
and newfile2:
zip old_archive newfile1 newfile2 --out new_archive
Cannot update split archive, so use --out to out new archive:
zip in_split_archive newfile1 newfile2 --out out_split_archive
If input is split, output will default to same split size
Use -s=0 or -s- to turn off splitting to convert split to single file:
zip in_split_archive -s 0 --out out_single_file_archive
WARNING: If overwriting old split archive but need less splits,
old splits not overwritten are not needed but remain

Copy Mode (copying from archive to archive):
-U (also --copy) select entries in archive to copy (reverse delete)
Copy Mode copies entries from old to new archive with --out and is used by
zip when either no input files on command line or -U (--copy) used.
zip inarchive --copy pattern pattern ... --out outarchive
To copy only files matching *.c into new archive, excluding foo.c:
zip old_archive --copy "*.c" --out new_archive -x foo.c
If no input files and --out, copy all entries in old archive:
zip old_archive --out new_archive

Streaming and FIFOs:
prog1 | zip -ll z - zip output of prog1 to zipfile z, converting CR LF
zip - -R "*.c" | prog2 zip *.c files in current dir and stream to prog2
prog1 | zip | prog2 zip in pipe with no in or out acts like zip - -
If Zip is Zip64 enabled, streaming stdin creates Zip64 archives by default
that need PKZip 4.5 unzipper like UnZip 6.0
WARNING: Some archives created with streaming use data descriptors and
should work with most unzips but may not work with some
Can use -fz- to turn off Zip64 if input not large (< 4 GB):
prog_with_small_output | zip archive -fz-

Zip now can read Unix FIFO (named pipes). Off by default to prevent zip
from stopping unexpectedly on unfed pipe, use -FI to enable:
zip -FI archive fifo

Dots, counts:
-db display running count of bytes processed and bytes to go
(uncompressed size, except delete and copy show stored size)
-dc display running count of entries done and entries to go
-dd display dots every 10 MB (or dot size) while processing files
-dg display dots globally for archive instead of for each file
zip -qdgds 10m will turn off most output except dots every 10 MB
-ds siz each dot is siz processed where siz is nm as splits (0 no dots)
-du display original uncompressed size for each entry as added
-dv display volume (disk) number in format in_disk>out_disk
Dot size is approximate, especially for dot sizes less than 1 MB
Dot options don't apply to Scanning files dots (dot/2sec) (-q turns off)

-lf path open file at path as logfile (overwrite existing file)
-la append to existing logfile
-li include info messages (default just warnings and errors)

Testing archives:
-T test completed temp archive with unzip before updating archive
-TT cmd use command cmd instead of 'unzip -tqq' to test archive
On Unix, to use unzip in current directory, could use:
zip archive file1 file2 -T -TT "./unzip -tqq"
In cmd, {} replaced by temp archive path, else temp appended.
The return code is checked for success (0 on Unix)

Fixing archives:
-F attempt to fix a mostly intact archive (try this first)
-FF try to salvage what can (may get more but less reliable)
Fix options copy entries from potentially bad archive to new archive.
-F tries to read archive normally and copy only intact entries, while
-FF tries to salvage what can and may result in incomplete entries.
Must use --out option to specify output archive:
zip -F --out
Use -v (verbose) with -FF to see details:
zip -FF -v --out
Currently neither option fixes bad entries, as from text mode ftp get.

Difference mode:
-DF (also --dif) only include files that have changed or are
new as compared to the input archive
Difference mode can be used to create incremental backups. For example:
zip --dif -r somedir --out
will store all new files, as well as any files in where
either file time or size have changed from that in,
in new Output archive not excluded automatically if exists,
so either use -x to exclude it or put outside what is being zipped.

DOS Archive bit (Windows only):
-AS include only files with the DOS Archive bit set
-AC after archive created, clear archive bit of included files
WARNING: Once the archive bits are cleared they are cleared
Use -T to test the archive before the bits are cleared
Can also use -sf to save file list before zipping files

Show files:
-sf show files to operate on and exit (-sf- logfile only)
-su as -sf but show escaped UTF-8 Unicode names also if exist
-sU as -sf but show escaped UTF-8 Unicode names instead
Any character not in the current locale is escaped as #Uxxxx, where x
is hex digit, if 16-bit code is sufficient, or #Lxxxxxx if 24-bits
are needed. If add -UN=e, Zip escapes all non-ASCII characters.

If compiled with Unicode support, Zip stores UTF-8 path of entries.
This is backward compatible. Unicode paths allow better conversion
of entry names between different character sets.

New Unicode extra field includes checksum to verify Unicode path
goes with standard path for that entry (as utilities like ZipNote
can rename entries). If these do not match, use below options to
set what Zip does:
-UN=Quit - if mismatch, exit with error
-UN=Warn - if mismatch, warn, ignore UTF-8 (default)
-UN=Ignore - if mismatch, quietly ignore UTF-8
-UN=No - ignore any UTF-8 paths, use standard paths for all
An exception to -UN=N are entries with new UTF-8 bit set (instead
of using extra fields). These are always handled as Unicode.

Normally Zip escapes all chars outside current char set, but leaves
as is supported chars, which may not be OK in path names. -UN=Escape
escapes any character not ASCII:
zip -sU -UN=e archive
Can use either normal path or escaped Unicode path on command line
to match files in archive.

Zip now stores UTF-8 in entry path and comment fields on systems
where UTF-8 char set is default, such as most modern Unix, and
and on other systems in new extra fields with escaped versions in
entry path and comment fields for backward compatibility.
Option -UN=UTF8 will force storing UTF-8 in entry path and comment
-UN=UTF8 - store UTF-8 in entry path and comment fields
This option can be useful for multi-byte char sets on Windows where
escaped paths and comments can be too long to be valid as the UTF-8
versions tend to be shorter.

Only UTF-8 comments on UTF-8 native systems supported. UTF-8 comments
for other systems planned in next release.

Self extractor:
-A Adjust offsets - a self extractor is created by prepending
the extractor executable to archive, but internal offsets
are then off. Use -A to fix offsets.
-J Junk sfx - removes prepended extractor executable from
self extractor, leaving a plain zip archive.

More option highlights (see manual for additional options and details):
-b dir when creating or updating archive, create the temp archive in
dir, which allows using seekable temp file when writing to a
write once CD, such archives compatible with more unzips
(could require additional file copy if on another device)
-MM input patterns must match at least one file and matched files
must be readable or exit with OPEN error and abort archive
(without -MM, both are warnings only, and if unreadable files
are skipped OPEN error (18) returned after archive created)
-nw no wildcards (wildcards are like any other character)
-sc show command line arguments as processed and exit
-sd show debugging as Zip does each step
-so show all available options on this system
-X default=strip old extra fields, -X- keep old, -X strip most
-ws wildcards don't span directory boundaries in paths

絶対パスで圧縮実行 / 相対パスで圧縮実行 / 一つ上の階層を相対パスで指定して、圧縮実行

 閲覧数:240 投稿日:2019-08-13 更新日:2019-08-13 


$ zip -r /var/www/hoge



$ cd /var/www;
$ zip -r ./hoge;



$ cd /var/www/hoge;
$ zip -r ../hoge;


階層構造で圧縮しないためには? / -o オプション / 未解決

 閲覧数:216 投稿日:2019-08-13 更新日:2019-08-13 




-o オプション

-o 圧縮ファイルの変更時刻を,指定したファイルのうちもっとも新しいものと同じにする

・zipファイル内の「作成日時」は、zip解凍日時へ自動変更される(-o オプション付与有無の影響を受けない)

-o オプション付与する場合

-o オプション付与しない場合

同じやん! どういうことなの?





淡雪 @namaridama_zip
塩素まみれのりゅうじくん @Zip_a_Disney
AQ🐧 @aq_poker
まつはや @matsuhaya
あるみほいるせんせい @zip_rock
塩素まみれのりゅうじくん @Zip_a_Disney
ちこ太郎.zip @chikotarou_zip
作業環境 2022/10/05 20:35
薫風 @bar_kunpu

順位 ページタイトル抜粋
1 Graphviz 55
2 Options 40
3 cp 40
4 vi 40
5 npm 33
6 Vim 33
7 top 33
8 info 29
9 rmdir 25
10 mailx 25
11 paste 25
12 mkdir 22
13 Basic認証 20
14 Postfix 20
15 history 20
16 php.ini / CentOS 6 19
17 CasperJS 18
18 npmアップデート 17
19 Linuxコマンド 17
20 configure 17
2022/10/05 20:39 更新
週間人気ページランキング / 9-28 → 10-4
順位 ページタイトル抜粋 アクセス数
0 さくらVPS0 18
0 PHP実行ユーザ設定 / CentOS6 / Apache | PHP(プログラミング言語) 18
1 PHPのmb_send_mail関数でメール送信できない | メール処理システム 17
2 phpの設定ファイルをphp.ini から分離させても良いの? 12
3 Nginx設定。エラーログレベル | Nginx(Webサーバ) 11
4 「RLogin」で文字化けするようになった場合は、オプション設定 - フォント - 文字セット -「UTF-8」を選択します。  | RLogin(ターミナルエミュレータ) 9
4 ImageMagick と imagick の違い | ImageMagick(ソフトウェアスイート) 9
5 FFmpeg 2.8.15 を yum インストール | ソフトウェアスイート 8
5 ABRT により 問題が検出されました | CentOS 7 (CentOS) 8
5 Python 3.5 アンインストール / yum remove | Python(プログラミング言語) 8
6 echo と cat の違い 7
6 Bearerとは? / Bearer Token とは? / 基本的な使い方 7
6 Postfix | メール処理システム 7
6 ImageMagick を yum アンインストール / ImageMagick 6.8.8-9 を make アンインストール | ImageMagick(ソフトウェアスイート) 7
7 PHP実行ユーザ設定 / CentOS7 / Nginx | PHP(プログラミング言語) 6
7 Sandboxモードを使うことができるsaharaプラグインを使ってみる 6
7 バーチャルホスト設定には細心の注意を! | バーチャルホスト(Apache) 6
7 grep -rl 置換前文字列 . | xargs sed -i 's/置換前文字列/置換後文字列/g' 6
7 touch コマンド / viコマンド。新規ファイル作成時の違い | Linuxコマンド 6
7 設定 2019/1/22 / 一般ユーザがmailコマンドでメール送信 / 管理者がmailコマンドでメール送信 6
2022/10/5 1:01 更新