Find the answer to your Linux question:
Results 1 to 4 of 4
I am using the following script to rename all file in a directory. for i in *; do mv "$i" "$(date +%Y_%m_$(echo $i |sed s/file// |sed s/.jpg//))".jpg; done I just ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    4

    Talking rename files I am stuck

    I am using the following script to rename all file in a directory.

    for i in *;
    do mv "$i" "$(date +%Y_%m_$(echo $i |sed s/file// |sed s/.jpg//))".jpg;
    done

    I just want the Date/Time stamp in the filename, not Date/Time/originalfilename.
    I want to drop the original filename when the files are renamed.

    Please Help I am stuck.

  2. #2
    Just Joined! AdmiralBeotch's Avatar
    Join Date
    Feb 2009
    Location
    Las Vegas, NV
    Posts
    17
    This will work and help you avoid collisions in filenames:
    Code:
    for i in *; do echo mv "$i" "$(date +%Y_%m_)$RANDOM"; done
    I coudnt definitively tell, but were you trying to keep the file extension?
    Are they always going to be jpg files, or could it be any file type?

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Posts
    4
    Yes they are always JPG's thanks your code works great.

  4. #4
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Hi jimaki141, I didn't spot your post in the other thread. Did you get the space handling sorted out or was that still causing problems?

Posting Permissions

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