In bash (not plain sh), you can use the
**/ wildcard pattern to traverse directories recursively. You need to set the
globstar option first. For example, to run
mycommand on every
.fastq file under
shopt -s globstar
for x in /project/samples/**/*.fastq; do
This is only available since bash 4.0 (so not on the default bash on OSX, but the feature is also available in zsh). In bash versions before 4.3, beware that it also traverses symbolic links to directories.
If you need to run a single command on all the files, you can:
However you may run into a limit on the length of the command line. It helps to use a relative path:
If that still doesn't fit, you'll need to find another solution to do whatever you need to do, that doesn't involve passing all the file names as arguments to that command at once.