Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    2

    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...
    fdfsdfsdfscommonffsdfsfsf
    tyryrtryryrycommondasdadad
    poirpoipweripcommonuyuyqiey

    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

    thanks

  2. #2
    Just Joined!
    Join Date
    May 2011
    Location
    Central FL
    Posts
    91
    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:
    Code:
    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
    Just Joined!
    Join Date
    May 2013
    Posts
    2
    Thanks Dayid, the date and time are the create time of the file.

Posting Permissions

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