Skip to content
Latchkey

zip -j: Junk Paths and Flatten an Archive

zip -j (junk paths) stores each file by its base name only, discarding the directory structure.

Some deploy targets want a flat archive with no nested folders. -j collapses the tree, but watch for two files with the same name overwriting each other.

What it does

zip -j strips the directory component from every entry, storing files at the archive root by their base names. A file at src/util/log.js is stored simply as log.js. Directory entries are not created.

Common usage

Terminal
# flatten all matched files into the archive root
zip -j flat.zip src/util/log.js src/app/main.js
# flatten a directory of files
zip -j -r assets.zip dist/assets

Options

FlagWhat it does
-jJunk (drop) the directory paths, store base names only
-rRecurse into directories
-qQuiet output
-x <pattern>Exclude paths from the input

In CI

Flattening is useful when a consumer expects files at the top level, but it is dangerous when names repeat. If two inputs share a base name, the second overwrites the first inside the archive. Confirm names are unique before relying on -j, or keep the paths and use -j only on a curated file list.

Common errors in CI

The quiet failure mode is silent name collision: src/a/config.json and src/b/config.json both become config.json and one is lost without an obvious error. Check the entry count with unzip -l afterward. -j also drops the path needed by tools that expect a specific layout, such as the Lambda handler path, so do not flatten a deployment package.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →