Extracting to a directory other than the current directory with pax archiver

directorypax

I have a strange behaviour with the pax archiver here, had too much troubles with tar and it's absolute path, that's why I gave pax a shot.
The below oneliner is used under FreeBSD 9.2 to extract encrypted archives. Basically it works quite well, but when trying to extract the archive to another path than the working directory, I get the error message:

WARNING! These patterns were not matched:
/home/myuser/testing

Example:

    cd /home/myuser

    gpg --no-tty --quiet --no-secmem-warning --yes --batch --passphrase-file /home/myuser/keyfile --decrypt /home/myuser/testing/20110426.pax.xz.gpg | unxz | pax -r 
    # SUCCESS                                                                                                                                                 # SUCCESS

    gpg --no-tty --quiet --no-secmem-warning --yes --batch --passphrase-file /home/myuser/keyfile --decrypt /home/myuser/testing/20110426.pax.xz.gpg | unxz | pax -r /home/myuser
    # SUCCESS                                                                                                                                                 # SUCCESS

    gpg --no-tty --quiet --no-secmem-warning --yes --batch --passphrase-file /home/myuser/keyfile --decrypt /home/myuser/testing/20110426.pax.xz.gpg | unxz | pax -r /home/myuser/testing
    # FAILS                                                                                                                                                   # FAILS

    gpg --no-tty --quiet --no-secmem-warning --yes --batch --passphrase-file /home/myuser/keyfile --decrypt /home/myuser/testing/20110426.pax.xz.gpg | unxz | pax -r /home/myuser/testing/
    # FAILS                                                                                                                                                   # FAILS

There is definately write permission on /home/myuser/testing/ on top of that, I'm executing it as root.

Does that really "works as designed" and I have to cd /output/path before each extraction or am doing something wrong?

Best Answer

The argument to pax is a path inside the archive. The usual idiom if you want to unpack under a different directory is to change to the directory where you want to unpack.

… | { cd / && pax -r -pe; }

Another approach is to tell pax to rewrite the paths. This is especially useful when you want to strip some leading directories.

… | pax -s '!^/home/myuser!!' -r -pe
Related Question