Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm able to extract individual file rpm rpm by:

rpm2cpio rpm_name | cpio -ivd ./a/b/c/README

I need to extract the whole /a/b/c/ directory (using ./a/b/c/ in above command doesn't works)?

  1. How it can be done?
  2. Can I indicate where to create directory "c/" instead of ./a/b/c?
share|improve this question

migrated from Nov 22 '12 at 8:20

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted
  1. use a wildcard, but be careful to protect it from the shell:

    rpm2cpio rpm_name | cpio -ivd './a/b/c/*'

  2. Not directly, but cpio does have a -r/--rename switch. There are unfortunately two problems with that: it asks about each file and it takes input from /dev/tty directly. Which means it's not easy to automate it. You could use the expect program if you really wanted to do it. Warning: not for the faint of heart ;) Note that it doesn't handle files with quotes (or possibly spaces) properly. It expects the name of the rpm file, a pattern for the files to extract and a sed command to transform each file. Usage example: rpm_name './a/b/c/*' 's#^./a/b/#foo/#'

Theoretically the script could be piped into expect but that's left as an excercise for the reader.

#! /bin/bash


echo "spawn sh -c \"rpm2cpio \\\"$RPM\\\" | cpio -ird '$FILES'\"" > "$SCRIPT"
rpm2cpio "$RPM" | cpio -it "$FILES" 2>/dev/null | sed "$TRANSFORM" | while read line
    echo "send \"$line\\r\"" >> "$SCRIPT"
echo "wait" >> "$SCRIPT"
expect "$SCRIPT"
rm -f "$SCRIPT"
share|improve this answer
Your 1st solution is what I was looking for. Thanks – dimba Nov 21 '12 at 6:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.