1

This seems like the kind of question that could be found in the man for ditto, but I've read that and googled this question with no answer.

I simply want to archive a few files using ditto, like this:

ditto -ckv file1 file2 file3 newfile.zip

It seems that ditto allows for multiple source files. But I get an error.

Does anyone if there's a way to make this work or can you confirm that ditto won't allow this?

Wayne F. Kaskie
  • 3,257
  • 5
  • 33
  • 43

2 Answers2

2

Updated Answer

You can do that with built-in zip command:

zip archive.zip file1 file2 file3

or, more simply:

zip archive.zip file[123]

Original Answer

You can do that with 7zip.


Here I write (add) 3 files to an archive:

7z a archive.zip file1 file2 file3

Now, I check what's in it:

7z l archive.zip 

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)

Scanning the drive for archives:
1 file, 2827 bytes (3 KiB)

Listing archive: archive.zip

--
Path = archive.zip
Type = zip
Physical Size = 2827

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2017-06-19 21:48:35 .....         1684          811  file1
2017-06-19 21:48:39 .....         1690          813  file2
2017-06-19 21:48:41 .....         1696          815  file3
------------------- ----- ------------ ------------  ------------------------
2017-06-19 21:48:41               5070         2439  3 files

I could equally check the contents with unzip:

unzip -l archive.zip 

Archive:  archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     1684  06-19-2017 21:48   file1
     1690  06-19-2017 21:48   file2
     1696  06-19-2017 21:48   file3
---------                     -------
     5070                     3 files

I installed 7zip with homebrew using:

brew install p7zip
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks for the detailed reply! I assume it can't be done with ditto, but given that zip is just another built-in command, I can use it instead. – Wayne F. Kaskie Jun 21 '17 at 15:58
  • `zip` can corrupt the contents of a signed app bundle, "destroying the UTF8 encoding." See [this thread](https://developer.apple.com/forums/thread/116831). – Carl Walsh Mar 20 '23 at 17:39
0

The manual suggest that only one source file system object can create an archive.

ditto -c [-z | -j | -k] [-v] [-V] [-X] [<options>] src dst_archive

To copy multiple files, you could copy files or hard link files to a directory then zip the directory with ditto.

fd0
  • 289
  • 7
  • 10
  • Thanks for confirming that it can't be done with ditto. I'm using a bash script to work with existing folder structures, so moving the files around wouldn't work for this particular situation. – Wayne F. Kaskie Jun 21 '17 at 15:59