Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    search for same filename in different directories and rename

    Hi, I am new to bash scripting and trying to search for a filename xyz.csv.gz which is in multiple directories with a common element in the directory name. eg

    xyz.csv.gz is in the following directories ????common???

    directories like this...

    How do I search, rename and copy the xyz.csv.gz (of which there are many the same name) to 15-05-2013-16:04_xyz.csv.gz (date & time) to /output


  2. #2
    Just Joined!
    Join Date
    May 2011
    Austin, TX
    Will they all be using the same date or are you trying to use the modification time or something? Otherwise, creating a bunch of /output/15-05-2013-16:04_xyz.csv.gz will just overwrite it over and over...

    To get you started:
    cd /whatever-directory-they-are-in/
    find ./*common*/ -name "xyz.csv.gz" -exec cp '{}' /output/15-05-2013-16:04_xyz.csv.gz \;
    ^ note that this will result in each being copied over the same filename, /output/15-05-2013-16:04_xyz.csv.gz. If you're using different times/dates, then you'll need to adjust/add a way of managing that.

  3. #3
    Thanks Dayid, the date and time are the create time of the file.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts