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
# 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/assetsOptions
| Flag | What it does |
|---|---|
| -j | Junk (drop) the directory paths, store base names only |
| -r | Recurse into directories |
| -q | Quiet 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.