I have a directory with hundreds of sub-directories with many .lib files in them. I am able to use the ar -x filename.lib command to unpack one of them, but I was wondering how one would do this recursively since there is no built in recursive flag according to man ar. Right now I am trying to do

find . -name '*.lib' -exec ar -x {} +

but I get a message saying for every file no entry filename.lib in archive. I googled this error but I could not find anything relevant, and my current method of doing it is based off of this question's answers (namely the 2nd one and its comments), but clearly it is not working. Any ideas as to what I am doing wrong?

  • Meta-note: there is no such thing as "the 2nd answer". Any user can order answers by "votes", "oldest" or "active" on their own; votes change, activity gets updated… – Kamil Maciorowski Jul 12 at 20:02
  • @KamilMaciorowski my bad, fixed the question and was referring to 2nd one by votes, which because the question is old will probably be the second answer for a while. – Alerra Jul 12 at 20:08
up vote 1 down vote accepted

man 1 ar says the syntax is

ar [--plugin name] [-X32_64] [-]p[mod [relpos] [count]] archive [member...]

So it works with one archive at a time, the extra arguments are members. You obviously don't want to specify members.

find … -exec … {} + substitutes {} with mutliple paths. Excessive paths are interpreted as members by ar. You need find … -exec … {} … \; which subsitutes {} with just one path.

find . -name '*.lib' -exec ar -x {} \;

This way every file found is passed to a separate ar and satisfies its requirement for just one archive.

Note: -execdir may or may not be better for you. Refer to man 1 find to learn the difference.

  • Wow! Thanks for the detailed and quick answer. I'm also glad to know that my original answer wasn't too far off. – Alerra Jul 12 at 20:11

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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