#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Renaming a file when I only know part of the filename


    Hi,

    I am a UNIX newbie. I need help renaming a file when I only know part of the filename. I know the file will look like:

    My_report_"YYYY_MM_DD_timestamp".csv

    I get a copy of the report each day with the timestamp of when the file was created. I know it is created each day, but the timestamp can vary. I want to FTP the file to another directory and remove the timestamp portion so the resulting file would look like

    My_report_"YYYY_MM_DD".csv

    I tried setting up some variables for date, but when I try to use them I get

    My_report_date not found instead of it translating to the variable I setup as

    My_report_2012_10_16

    Please help.

    Thanks,
    ~Rehlow
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,111
    Rep Power
    487
    What about something like

    Code:
    STAMP=$(date +"%Y-%m-%d")
    mv /source/folder/My_report* /new/folder/My_report_$STAMP.csv

    ?
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by badger_fruit
    What about something like

    Code:
    STAMP=$(date +"%Y-%m-%d")
    mv /source/folder/My_report* /new/folder/My_report_$STAMP.csv

    ?
    That worked. Thanks. With my prior attempt I was declaring my variable incorrectly (that's what I get for borrowing someone else's code).

    Thanks again,
    ~Rehlow

IMN logo majestic logo threadwatch logo seochat tools logo