Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH - execute command for all files with some extension

Tags:

bash

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!

like image 640
Trenera Avatar asked Apr 26 '26 18:04

Trenera


1 Answers

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. ;-)

like image 126
DevSolar Avatar answered Apr 28 '26 13:04

DevSolar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!