title: Bash script to scan sub-directories and copy contents of file to another file
body: <p>I need to do a bash command that will look through every home directory on a system, and copy the contents of the .forward file to a single file, along with copying the name of the directory it just copied from.  So for example the final file would be something like forwards.txt and listeings would be</p>
  
  <pre><code>/home/user1
  user1@email.com
  /home/user2
  user2@email.com
  </code></pre>
  
  <p>I've used this to list them to screen.</p>
  
  <pre><code>find /home -name '*' | cat /home/*/.forward
  </code></pre>
  
  <p>and it will print out the forward in each file but I'm not getting it to prefix it with which home directory it came from. Would I need to use a loop to do this?  I had this test loop,</p>
  
  <pre><code>#!/bin/bash
  for i in /home/*
          do
                  if [ -d $i ]
                          then
                                  pwd &gt;&gt; /tmp/forwards.txt
                                  cat /home/*/.forward &gt;&gt; /tmp/forwards.txt
                  fi
          done
  </code></pre>
  
  <p>But it went through the four home directories on my test setup and the forwards.txt file had the following listed four times.</p>
  
  <pre><code>/tmp
  user1@email.com
  user2@email.com
  user3@email.com
  user3@email.com
  </code></pre>
  
  <p>Thanks. </p>