使用Bash批量重命名文件 [英] Batch renaming files with Bash

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

问题描述

Bash如何重命名一系列软件包以删除其版本号?我一直在玩弄expr%%,都无济于事.

How can Bash rename a series of packages to remove their version numbers? I've been toying around with both expr and %%, to no avail.

示例:

Xft2-2.1.13.pkg变为Xft2.pkg

jasper-1.900.1.pkg变为jasper.pkg

xorg-libXrandr-1.2.3.pkg变为xorg-libXrandr.pkg

推荐答案

您可以使用bash的参数扩展功能

You could use bash's parameter expansion feature

for i in ./*.pkg ; do mv "$i" "${i/-[0-9.]*.pkg/.pkg}" ; done

带空格的文件名需要引号.

Quotes are needed for filenames with spaces.

这篇关于使用Bash批量重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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