一次批量重命名文件和文件夹
我得到了有关以下问题的帮助: 批量重命名具有完整 ID 的文件
这是如何重命名特定文件的一个很好的示例在一个组中,但我想知道是否有一个类似的脚本可以用来执行以下操作:
- 我在根目录中有一组嵌套文件夹和文件,其中包含 [myprefix_foldername] 和[myprefix_filename.ext]
- 我想将所有文件夹和文件重命名为 [foldername] 和 [filename.ext]
我可以使用与上面帖子中类似的方法吗?
谢谢! 杰姆
I got help regarding the following question:
batch rename files with ids intact
It's a great example of how to rename specific files in a group, but I am wondering if there is a similar script I could use to do the following:
- I have a group of nested folders and files within a root directory that contain [myprefix_foldername] and [myprefix_filename.ext]
- I would like to rename all of the folders and files to [foldername] and [filename.ext]
Can I use a similar methodology to what is found in the post above?
Thanks!
jml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,非常容易,使用find。
这将为您提供
rootDir
中以myprefix_
开头的所有文件和文件夹的列表。从那里,可以快速跳转到批量重命名:编辑:
IFS
添加每个 http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html编辑2:
IFS
被删除,以支持while read
。编辑 3: 正如 bos 指出的,如果您的情况,您可能需要将
while read f
更改为while read -d $'\n' f
Bash 版本仍然不喜欢它。Yes, quite easily, with find.
This will give you a list of all files and folders in
rootDir
that start withmyprefix_
. From there, it's a short jump to a batch rename:EDIT:
IFS
added per http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.htmlEDIT 2:
IFS
removed in favor ofwhile read
.EDIT 3: As bos points out, you may need to change
while read f
towhile read -d $'\n' f
if your version of Bash still doesn't like it.