Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Saying, I have this tree and I want to execute ruby on all scripts within the folder. How could I archive through one line of command.

share|improve this question
up vote 9 down vote accepted

Something along the lines (depending on your shell) of

for file in rb-script/*.rb; do ruby "$file"; done

should do the trick; alternatively (and shell-independently, I think)

find rb-script -type f -exec ruby "{}" \;

using find; where you can, depending on your situation, be more specific, à la

find rb-script -maxdepth 1 -type f -name '*.rb' -exec ruby "{}" \;

In general, command <glob-pattern> would also work if command accepts several files (and there are less files than the commandline argument maximum of your shell), but I doubt ruby does that. (You could write a wrapper script such that ruby-wrapper rb-script/*.rb would do what you want, though.)

share|improve this answer
Thanks. Good tips for using ; to execute multiple commands. – steveyang Mar 10 '12 at 11:11

If this will be part of a daemon, you could use the run-parts command to execute everything in the folder in alphabetical order. This command is especially useful if you need to execute it in reverse order for shutdown.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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