How to move many files in multiple different directories (on Linux)

Posted by user1335982 on Stack Overflow See other posts from Stack Overflow or by user1335982
Published on 2012-04-16T10:12:26Z Indexed on 2012/04/16 11:29 UTC
Read the original article Hit count: 150

Filed under:
|
|
|
|

My problem is that I have too many files in single directory. I cannot "ls" the directory, cos is too large. I need to move all files in better directory structure.

I'm using the last 3 digits from ID as folders in reverse way.

For example ID 2018972 will gotta go in /2/7/9/img_2018972.jpg.

I've created the directories, but now I need help with bash script. I know the IDs, there are in range 1,300,000 - 2,000,000. But I can't handle regular expressions.

I wan't to move all files like this:

/images/folder/img_2018972.jpg -> /images/2/7/9/img_2018972.jpg

I will appreciate any help on this subject. Thanks!

© Stack Overflow or respective owner

Related posts about regex

Related posts about linux