applying the same command to multiple files in multiple subdirectories

148 views Asked by At

I have a directory with 94 subdirectories, each containing one or two files *.fastq. I need to apply the same python command to each of these files and produce a new file qc_*.fastq.

I know how to apply a bash script individually to each file, but I'm wondering if there is a way to write a bash script to apply the command to all the files at once

2

There are 2 answers

3
nanny On

Use find:

find . -type f -iname "*.fastq" -exec python script {} \;

.: The top-most directory

-type f: Only files

-iname "*.fastq": File name ends in .fastq (case insensitive)

-exec python script: The command you want to execute.

0
Ying Xiong On

You can try find . -name "*.fastq" | xargs your_bash_script.sh, which use find to get all the files and apply your script to each one of them.