Trenera
Trenera

Reputation: 1505

BASH - execute command for all files with some extension

I have to execute command in bash for all files in a folder with the extension ".prot'

The command is called "bezogener_Spannungsgradient" and it's called like that:

bezogener_Spannungsgradient filename.prot

Thanks!

Upvotes: 3

Views: 3500

Answers (2)

DevSolar
DevSolar

Reputation: 70391

find . -maxdepth 1 -name \*.prot -exec bezogener_Spannungsgradient {} \;

-maxdepth <depth> keeps find from recursing into subdirectories beyond the given depth.

-name <pattern> limits find to files matching the pattern. The escape is necessary to keep bash from expanding the find option into a list of matching files.

-exec <cmd> {} \; executes <cmd> on each found file (replacing {} with the filename). If the command is capable of processing a list of files, use + instead of \;.

I generally recommend becoming familiar with the lots of other options of find; it's one of the most underestimated tools out there. ;-)

Upvotes: 5

arco444
arco444

Reputation: 22871

You could do this:

for f in *.prot; do
  bezogener_Spannungsgradient "$f"
done

Upvotes: 3

Related Questions