Skip to content

Instantly share code, notes, and snippets.



Created Apr 26, 2018
What would you like to do?
I had a need the other day to read files out of RPM and DEB packages, but wanted to avoid extracting them to my local filesystem; the following scripts cobble together the various tools I found to simply read a single file from either to stdout.
#!/usr/bin/env bash -x
# prereq: tar
tar -xOf $package data.tar.gz | tar -zxO $file
#!/usr/bin/env bash -x
# prereq: rpm2cpio
# prereq: cpio (GNU-flavored); will auto-detect from `GNU_CPIO` env var, GNU-flavored `cpio` on path, or `gnu-cpio` on path
# detect GNU-flavored `cpio`, which supports reading to stdout:
# - IF `GNU_CPIO` set, trust it;
# - ELSE IF `cpio` on path is GNU, use it;
# - ELSE look for `gnu-cpio`
GNU_CPIO=${GNU_CPIO:-$(cpio --help | grep GNU >/dev/null && which cpio || which gnu-cpio)}
rpm2cpio $package | "${GNU_CPIO:?}" -iv --to-stdout $file 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment