bash Linux-Massive文件夹重命名 [英] bash Linux - Massive folder rename

查看:43
本文介绍了bash Linux-Massive文件夹重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux文件服务器(RedHat Enterprise)上,我们需要重命名一些包含客户端工作的文件夹.旧文件夹格式(需要更改的格式)为 clientcode_jobnumberjobname .新格式为 clientcode_jobnumber_jobname .我们基本上需要通过在 jobnumber jobname 之间的文件夹名称中添加额外的下划线来更改旧文件夹的名称.我们还拥有所有要创建的新文件夹结构,以新格式显示,因此无需更改它们.职位编号始终为1个字母,后跟4个数字.客户端代码是3–4个字母,具体取决于客户端.每个工作的工作名称都不同.这些文件夹都位于 clients/clientname/jobs/clientcode/需要重命名的文件夹" (只是该脚本必须深入结构的一个示例).它将需要对每个客户端下的每个 clientcode 执行此操作.我将如何设置脚本来执行此操作?任何帮助将不胜感激.我们有成千上万个需要重命名的文件夹.

On our Linux file server (RedHat Enterprise) we have some folders that we need to rename that have client work in them. The old folder format (ones that need to be changed) was clientcode_jobnumberjobname. The new format is clientcode_jobnumber_jobname. We basically need to change the old folder names by adding the extra underscore to the foldername between the jobnumber and jobname. We also have all the new folder structures that are being created to display in the new format so these will not need to be changed. The job number is always 1 letter followed by 4 numbers. The client code is 3–4 letters depending on the client. The job name is different for every job. The folders are all located at clients/clientname/jobs/clientcode/"folder that needs to be renamed" (just an example of how deep the script will have to go into the structure). It will need to do this for each clientcode under each client. How would I setup a script to do this? Any help would be greatly apprciated. We have thousands of these folders that we need to rename.

推荐答案

有些命令的作用类似于sed的文件名.尝试使用 mmv (或 rename 的perl变体,又名prename或named.PL,在RHEL上可能找不到).

There are a few commands that act like sed on file names; try mmv (or the perl variant of rename, aka prename or rename.PL, which you may not find on RHEL).

作为奖励,两者都具有 -n 选项(不起作用),因此您可以检查要做的事情不会破坏事物或丢失信息.

As a bonus, both have a -n option (no-act), so you can check what you're going to do isn't going to clobber things or lose information.

这篇关于bash Linux-Massive文件夹重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆