Results 1 to 3 of 3
  1. #1

    bash command: move files into newly created prefix-based folders

    I have a directory called "images" filled with about one million images.

    I want to write a shell command to rename all of those images into the following format:
    original: filename.jpg
    new: /f/i/l/filename.jpg

    Any suggestions?


  2. #2
    Join Date
    Apr 2003
    Los Angeles, CA
    for f in *; do mv $f ${f:0:1}/${f:1:1}/${f:2:1}/$f; done

    You may not be able to do a million files at once, though. Either use find with -exec {} or run the above in batches, like for f in 1* ... and 2* ...
    Pings <1 ms, Unlimited Transfer, Lowest Price: http://localhost/

  3. #3
    Thanks for the suggestion, luki. I'm actually waiting for all of the files to transfer to another server before I perform this operation. I also posted this question on stack overflow and got a few other options as well, for anyone interested:

Similar Threads

  1. Replies: 6
    Last Post: 06-21-2009, 12:20 PM
  2. [WHM/cPanel]500 Internal Server Error on all newly created account
    By KennyP in forum Hosting Software and Control Panels
    Replies: 1
    Last Post: 01-07-2008, 10:07 AM
  3. Copy newly created folders in /tmp
    By bear in forum Hosting Security and Technology
    Replies: 14
    Last Post: 04-04-2007, 03:05 PM
  4. URL for newly created virtual site
    By afriq in forum Dedicated Server
    Replies: 10
    Last Post: 06-25-2001, 10:46 PM

Posting Permissions

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