[英]centos Shell script to mv dynamic file names
I have the following file structure: 我具有以下文件结构:
/uploads/<blog_id>/10/155
For every blog_id there is a folder named 10
and inside that folder is another folder 155
. 对于每个blog_id,都有一个名为
10
的文件夹,并且在该文件夹内是另一个文件夹155
。 folder 155
has a bunch of files in it. 文件夹
155
有一堆文件。
I am simply trying to move all files from /10/155
to simply /10
for all blog_id
s. 我只是想将所有
blog_id
的所有文件从/10/155
blog_id
移动到/10
。
Basically, I just want to eliminate the 155
folder, moving its contents down into 10
. 基本上,我只想删除
155
文件夹,将其内容下移到10
。 I don't care if 155
stays there or is deleted. 我不在乎
155
留在那里或被删除。
I have tried several versions of this script: 我尝试了此脚本的多个版本:
for file in /var/www/html/uploads/*/10/155; do mv $file ${file%/*}/10; done
Ultimately, I was able to rename the 155 folder to 10 like: */10/10
. 最终,我能够将155文件夹重命名为10,例如:
*/10/10
。 I moved 155 down 2 levels (next to 10
) like: */155
. 我将155向下移动了2个级别(接近
10
个级别),例如: */155
。
Any help? 有什么帮助吗?
Just loop over the blog_id directories. 只需遍历blog_id目录。 Then for each of those you can do what you need:
然后,对于每个人,您都可以做您需要的事情:
for blog_dir in /uploads/*; do
mv "$blog_dir"/10/155/* "$blog_dir"/10/
rmdir "$blog_dir"/10/155
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.