Reputation: 25
We have a large number of files in a directory which need to be processed by a program called process
, which takes two aguments infile and outfile.
We want to name the outfile after infile and add a suffix. E.g. for processing a single file, we would do:
process somefile123 somefile123-processed
How can we process all files at once from the command line? (This is in a bash command line)
Upvotes: 0
Views: 95
Reputation: 207465
As @Cyrus says in the comments, the usual way to do that would be:
for f in *; do process "$f" "${f}-processed" & done
However, that may be undesirable and lead to a "thundering herd" of processes if you have thousands of files, so you might consider GNU Parallel which is:
and by default runs one process per CPU core to keep them all busy. So, that would become:
parallel process {} {}-processed ::: *
Upvotes: 1