Sourcing and opening multiple files of same name, in specified folder, in Terminal? Is there a way

command linefileterminal

Say I open terminal and change directory to folder 'folder', I type

cd folder. 

Say there're multiple folders within this folder, i.e. data 1, data 2, data 3, etc., and within each of those is an image named 'image_a'. Is there a way to source all of the 'image_a' files, and open them via command line? Or write a script/run a function that does?

This part may be irrelevant, but they're NIfTI gzip (.nii.gz) files that I'll open via FSLview. The syntax to open a single image is

fslview </file>

Best Answer

It depends on whether fslview accepts several filenames at once and does the right thing based on that (the documentation/man page should have more details on this). If yes, you can run

cd folder
fslview data*/image_a

to have it open all files at once. If no, you can use

cd folder
for f in data*; do fslview "$f"/image_a; done

or

cd folder
for f in data*/image_a; do fslview "$f"; done

instead (the second option works better if there are data X directories which don't contain image_a).

PS: For a test run, replace fslview with echo fslview to see which command(s) would be executed.