Find the answer to your Linux question:
Results 1 to 3 of 3
Hi gurus. I need to rename all files called 'monday_moved' to 'monday'. The following works find . -type f -name 'monday_moved' | while read filename; do mv -v "${filename}" "`echo ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    2

    Help to rename a file with a date


    Hi gurus.

    I need to rename all files called 'monday_moved' to 'monday'.

    The following works
    find . -type f -name 'monday_moved' | while read filename; do mv -v "${filename}" "`echo "${filename}" | sed -e 's/\monday_moved$/\monday/'`"; done

    But now I would like to move it to 'monday' with date, but they way I am doing it isnt working :
    find . -type f -name 'monday_moved' | while read filename; do mv -v "${filename}" "`echo "${filename}" | sed -e 's/\monday_moved$/\monday_`date +%F_%H_%M_%S`'`"; done

    bash: command substitution: line 186: unexpected EOF while looking for matching `''
    bash: command substitution: line 187: syntax error: unexpected end of file
    bash: command substitution: line 186: unexpected EOF while looking for matching `''
    bash: command substitution: line 187: syntax error: unexpected end of file
    `./oacore1/monday_moved' -> `date +%F_%H_%M_%S'

    (This also removes the monday_moved file from the sub directory).
    Coould someone please let me know where I am going wrong?

    Thanks.

    Roger.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,639
    Look into the "rename" command - see the man page.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    May 2013
    Posts
    2
    yes, I did check the rename, but the man page is really scant.
    the mv is working but with the `date +%F_%H_%M_%S` it is failing and I would like to understand why.
    thanks.

Posting Permissions

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