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>

2 Answers 2


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


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.


Try each of these

fslview image_a*

open image_a*

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .