3

I have a project with 500k users in CentOS. The picture file/directory structure was setup like this (yeah... i know):

  • user/0070/ this is the user ID / 1000, so that all users in the range of [70000-70999] are inside this directory
  • user/0070/70909/ this is the user ID
  • user/0070/70909/p.jpg profile picture (100x100)
  • user/0070/70909/x.jpg full size picture

I'm moving everything to a CDN, so I need to convert that structure into this:

  • user/70909.p.jpg profile picture (100x100)
  • user/70909.x.jpg full size picture

Of course, the only way to achieve that in a period of time is to execute a script that renames and moves all files inside one single directory. Any ideas? Thanks!

Martin Prikryl
  • 7,756
  • 2
  • 39
  • 73
Carlos Santos
  • 43
  • 1
  • 1
  • 11

1 Answers1

2

In bash:

cd user
for i in *; do
    for j in $i/*; do
        for k in $j/*; do
            mv $k `basename $j`.`basename $k`
        done
    done
done
Craig Miskell
  • 4,216
  • 1
  • 16
  • 16