<p>Tinkered a bit and realized the solution did not neccistate a for loop.</p>
<pre><code>mkdir ~/ST_0075/alignment; cp ~/ST_0075/annotations/*/*.gff ~/ST_0075/alignment
</code></pre>

CC BY-SA 4.0
2021-07-12T16:59:21.340Z
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.
terdon
CC BY-SA 4.0
2021-07-12T17:52:10.323Z
Hi @terdon, is it `**` that is doing the trick?
haci
CC BY-SA 4.0
2021-07-12T17:56:49.480Z
Yes, try `man bash | grep -A3 'globstar$'` to see the details.
terdon
CC BY-SA 4.0
2021-07-12T16:12:29.480Z
2021-07-12T16:12:29.480Z
MicroBiostat
<p>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.</p>
<p>However the following code does not seem to work:</p>
<pre><code>for pathname in &quot;~/ST_0075/annotations/*/*.gff&quot;; do cp &quot;$pathname&quot; ~/ST_0075/alignment; done
</code></pre>
<p>The directory structure is the following:</p>
<pre><code>Home
-ST_0075
---Annotations
-----Sample_001
----------001.gff
</code></pre>
<p>The goal is to copy from multiple Sample_XXX subdirectories within <code>Annotations</code> the XXX.gff files into another directory named <code>alignment</code></p>

<linux><data-management>
Copying files from multiple directories to a single
# Copying files from multiple directories to a single

(Asked by: username_0 on 2021-07-12)

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:
Home
-ST_0075
---Annotations
-----Sample_001
----------001.gff

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

**Tags:** linux, data-management

---

## 1 answers

### Answer by username_0 on 2021-07-12. Score: 3

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

> **Comments:**
> **username_1**: 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.  
> **username_2**: Hi @terdon, is it `**` that is doing the trick?  
> **username_1**: Yes, try `man bash | grep -A3 'globstar$'` to see the details.  

---

