I have multiple .GFF files, each in a single directory per annotated whole genome, that I wish to copy into a single directory so that I can perform a core genome alignment.

However the following code does not seem to work:

for pathname in "~/ST_0075/annotations/*/*.gff"; do cp "$pathname" ~/ST_0075/alignment; done

The directory structure is the following:


The goal is to copy from multiple Sample_XXX subdirectories within Annotations the XXX.gff files into another directory named alignment


1 Answer 1


Tinkered a bit and realized the solution did not neccistate a for loop.

mkdir ~/ST_0075/alignment; cp ~/ST_0075/annotations/*/*.gff ~/ST_0075/alignment
  • 3
    $\begingroup$ Exactly, and thanks for posting an answer! Note that if you're using bash, you can make it even simpler if you enable globstar. You can do: shopt -s globstar; cp ~/ST_0075/annotations/**/*.gff ~/ST_0075/alignment and that will recurse an arbitrary number of directories under annotations, so you don't need to count the exact number of */ you need. $\endgroup$
    – terdon
    Jul 12, 2021 at 16:59
  • $\begingroup$ Hi @terdon, is it ** that is doing the trick? $\endgroup$
    – haci
    Jul 12, 2021 at 17:52
  • 1
    $\begingroup$ Yes, try man bash | grep -A3 'globstar$' to see the details. $\endgroup$
    – terdon
    Jul 12, 2021 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.