Linux:将100万个文件移动到基于前缀的已创建文件夹中 [英] Linux: Move 1 million files into prefix-based created Folders
问题描述
我有一个名为 images的目录,其中充满了大约一百万个图像。是的。
I have a directory called "images" filled with about one million images. Yep.
我想编写一个shell命令将所有这些图像重命名为以下格式:
I want to write a shell command to rename all of those images into the following format:
原始: filename.jpg
新功能: / f / i / l / filename.jpg
有什么建议吗?
谢谢,< br>
Dan
Thanks,
Dan
推荐答案
for i in *.*; do mkdir -p ${i:0:1}/${i:1:1}/${i:2:1}/; mv $i ${i:0:1}/${i:1:1}/${i:2:1}/; done;
$ {i:0:1} / $ {i:1 :1} / $ {i:2:1}
部分可能是一个变量,或者更短或更短,但是上面的命令可以完成工作。您可能会遇到性能问题,但是如果您真的想使用它,请将 *。*
缩小为更少的选项( a *。*
, b *。*
或适合您的内容)
The ${i:0:1}/${i:1:1}/${i:2:1}
part could probably be a variable, or shorter or different, but the command above gets the job done. You'll probably face performance issues but if you really want to use it, narrow the *.*
to fewer options (a*.*
, b*.*
or what fits you)
编辑:添加了<$ c如Dan
edit: added a $
before i
for mv
, as noted by Dan
这篇关于Linux:将100万个文件移动到基于前缀的已创建文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!