Is there a way to zip all files in a given directory with the zip
command? I've heard of using *.*
, but I want it to work for extensionless files, too.
Command Line – How to Zip All Files in Directory
command linewildcardszip
command linewildcardszip
Is there a way to zip all files in a given directory with the zip
command? I've heard of using *.*
, but I want it to work for extensionless files, too.
Best Answer
You can just use
*
; there is no need for*.*
. File extensions are not special on Unix.*
matches zero or more characters—including a dot. So it matchesfoo.png
, because that's zero or more characters (seven, to be exact).Note that
*
by default doesn't match files beginning with a dot (neither does*.*
). This is often what you want. If not, in bash, if youshopt -s dotglob
it will (but will still exclude.
and..
). Other shells have different ways (or none at all) of including dotfiles.Alternatively,
zip
also has a-r
(recursive) option to do entire directory trees at once (and not have to worry about the dotfile problem):where
mydir
is the directory containing your files. Note that the produced zip will contain the directory structure as well as the files. As peterph points out in his comment, this is usually seen as a good thing: extracting the zip will neatly store all the extracted files in one subdirectory.You can also tell zip to not store the paths with the
-j
/--junk-paths
option.The
zip
command comes with documentation telling you about all of its (many) options; typeman zip
to see that documentation. This isn't unique to zip; you can get documentation for most commands this way.