ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
against all the files that match a specific criteria. I've tried various find syntax and I can't seem to get it right.
Normally I would just create a bash script and populate the results of find into an array and then just enumerate the collection but in this specific case I want to demonstrate this operation at the bash terminal.
if using 'find' then -exec is the way to go. If you pipe the output of another program to 'xargs' then this is how you can handle the substitutions explicitly:
Code:
... | xargs -I '{}' echo '{} and some other text'
If you do not specify the -I option then the piped input will just be appended at the end of the command that 'xargs' executes.
So the 'xargs' equivalent 'find -exec' in your initial post would be:
By the way, you don't need to use '{}' with -I; any character string will do*. I prefer using '@' myself, as it's not a reserved shell character and so doesn't need quoting.
Also remember to use the null separator when working with filenames that can contain spaces.
Notice that the "{}" must now appear exactly once, at the end of the command, and will expand to the entire list of filenames. So be sure that your command can handle that kind of input.
--
* Using gnu xargs and find, of course. Other implementations may not have the same features.
** Or as many as the command buffer will hold at a time, if the list is large.
Again, outstanding response! Thank you. Yea, this specific Java/Andriod application doesn't use named parameters so it expects a filepath as the first argument and an optional set of dimensions as the second argument. It doesn't understand a space delimited sequence of files and at first glance that's exactly what find was appearing to send in its output. Before I got your excellent response I was going to try a printf %s\n in the find to see if it functioned differently. Thankfully, I was just employing xargs incorrectly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.