title: Copying multiple files with same name in the same folder terminal script
body: <p>I have a lot of files named the same, with a directory structure (simplified) like this:</p>
  
  <pre><code> ../foo1/bar1/dir/file_1.ps  
   ../foo1/bar2/dir/file_1.ps  
   ../foo2/bar1/dir/file_1.ps
   .... and many more
  </code></pre>
  
  <p>As it is extremely inefficient to view all of those ps files by going to the 
  respective directory, I'd like to copy all of them into another directory, but include 
  the name of the first two directories (which are those relevant to my purpose) in the 
  file name. </p>
  
  <p>I have previously tried like this, but I cannot get which file is from where, as they 
  are all named consecutively:</p>
  
  <pre><code>#!/bin/bash -xv
  
  cp -v --backup=numbered {} */*/dir/file* ../plots/; 
  </code></pre>
  
  <p>Where <code>../plots</code> is the folder where I copy them. However, they are now of the form file.ps.~x~ (x is a number) so I get rid of the ".ps.~*~" and leave only the ps extension with:</p>
  
  <pre><code>rename 's/\.ps.~*~//g' *;
  rename 's/\~/.ps/g' *;
  </code></pre>
  
  <p>Then, as the ps files have hundreds of points sometimes and take a long time to open, I just transform them into jpg. </p>
  
  <pre><code>for file in * ; do convert -density 150 -quality 70 "$file" "${file/.ps/}".jpg; done;
  </code></pre>
  
  <p>This is not really a working bash script as I have to change the directory manually.</p>
  
  <p>I guess the best way to do it is to copy the files form the beginning with the names 
  of the first two directories incorporated in the copied filename.</p>
  
  <p>How can I do this last thing?</p>