How to include multiple files in ditto source

1.9k views Asked by At

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?

2

There are 2 answers

2
Mark Setchell On BEST ANSWER

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
1
fd0 On

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.