0

I remember seeing a unix command that would take lines from standard input and execute another command multiple times, with each line of input as the arguments. For the life of me I can't remember what the command was, but the syntax was something like this:

ls | multirun -r% rm %

In this case rm % was the command to run multiple times, and -r% was an option than means replace % with the input line (I don't remember what the real option was either, I'm just using -r as an example). The complete command would remove all files in the current by passing the name of each file in turn to rm (assuming, of course, that there are no directories in the current directory). What is the real name of multirun?

1 Answer 1

3

The command is called 'xargs' :-) and you can run it as following

ls | xargs echo I would love to rm -f the files

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! The correct full command would be ls | xargs -I% rm %
no need for %s in there... I don't think... man 1 xargs should give you the exact flavour on your system
Yes you're right, ls | xargs rm would do in this case, I guess when I saw the command before it was more complicated and only part of the arguments were given from standard in, so the -I% was necessary
Hmm, after some experimentation it looks like ls | xargs cmd is equivalent to cmd a b c (where a-c are the files in the current directory), whereas xargs -I% cmd % is equivalent to cmd a;cmd b;cmd c.
%x is a bad choice here, since it is expanded by the shell ( at least korn and bash shells, IIRC). Tip: avoid %.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.