
Assume you want to exclude file names with the extensions above, you could do excludeResults=() With the same syntax, one could use the results of the glob to exclude files of certain type. This could very well be expanded to have negate results also. of extensions *.gif, *.png and *.jpg, all you need to is ls -1 - **/+(*.jpg|*.gif|*.png) For example consider a case of needing to get all recursive image files i.e. similar to adding multiple flags in find command). file ending with multiple extension (i.e. This could very well be expanded to match multiple files i.e. Now for printing the actual files, just do printf '%s\n' an array and doing a proper quoted expansion is the right way when used in shell scripts, but for interactive use, you could simply use ls with the glob expression as ls -1 - **/*.csv The option ** is to recurse through the sub-folders and *.csv is glob expansion to include any file of the extensions mentioned. We use an array to populate the glob results because when quoted properly and expanded, the filenames with special characters would remain intact and not get broken due to word-splitting by the shell.įor example to list all the *.csv files in the recursive paths fileList=(**/*.csv) Now all you need to do is form the glob expression to include the files of a certain extension which you can do as below. And globstar that allows to recurse through all the directories shopt -s extglob nullglob globstar nullglob in which an unmatched glob is swept away entirely, replaced with a set of zero words. Additionally you could use couple of options more i.e.

The options are enabled with the -s support and disabled with he -u flag. The extended option is extglob which needs to be set using the shopt option as below. The bash shell provides an extended glob support option using which you can get the file names under recursive paths that match with the extensions you want.

Though using find command can be useful here, the shell itself provides options to achieve this requirement without any third party tools.
