Jon Jon - 1 year ago 88
Linux Question

how to ar x filename.a to different directory

Is there any ar option to extract objects to a different directory ?
Any way to extract them to tmp below ?

[test]# ls -l
total 1828
-rw-r--r-- 1 root root 1859628 Aug 24 02:10 libclsr11.a
drwxr-xr-x 2 root root 4096 Aug 24 02:12 tmp
[test]# ar x libclsr11.a
[test]# ls -l
total 3760
-rw-r--r-- 1 root root 157304 Aug 24 02:13 clsrcact.o
-rw-r--r-- 1 root root 19304 Aug 24 02:13 clsrcclu.o
-rw-r--r-- 1 root root 55696 Aug 24 02:13 clsrccss.o
drwxr-xr-x 2 root root 4096 Aug 24 02:12 tmp

Answer Source

Unfortunately, ar does not seem to provide a way to specify the directory where the files shall be extracted. (At least I was unable to find one.) It always uses the current directory. However, there is a simple workaround: Change to the target directory before extraction and use the relative path to the archive instead:

# cd ./tmp/
# ar x ../libclsr11.a

This way you should end up with clsrcact.o, clsrcclu.o and clsrccss.o inside the ./tmp/ directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download