借rename来吐槽一下

1,316次阅读
没有评论

共计 1537 个字符,预计需要花费 4 分钟才能阅读完成。

借rename来吐槽一下

起因

怎么说呢,今天新建了一个centos的虚拟机,准备安装hive的单机版本,碰巧centos 的官方镜像源关闭了,所以我要对此作一个处理。这中间就遇到一次批量文件名重命名这回事。

问题

其实这个问题也不是太大,需要处理的问题如下所示

[hadoop@localhost yum.repos.d]$ ls
CentOS-Linux-AppStream.repo.bak          CentOS-Linux-FastTrack.repo.bak
CentOS-Linux-BaseOS.repo.bak             CentOS-Linux-HighAvailability.repo.bak
CentOS-Linux-ContinuousRelease.repo.bak  CentOS-Linux-Media.repo.bak
CentOS-Linux-Debuginfo.repo.bak          CentOS-Linux-Plus.repo.bak
CentOS-Linux-Devel.repo.bak              CentOS-Linux-PowerTools.repo.bak
CentOS-Linux-Extras.repo.bak             CentOS-Linux-Sources.repo.bak

需要将上面.bak全部删除掉。

因此尝试使用 rename,博主linux的水平也是菜鸡的水平,网上搜了下给出的方法如下所示

rename  's/\.bak$//' *.bak

ok,使用之后毫无反应

那么问题出在哪了,我以为自己谷歌错了,然后我继续看了几个网页的介绍,不出意外全都是一样的解决方案。

心累,干脆自己研究一下rename,打开rename介绍

[hadoop@localhost yum.repos.d]$ rename --help

Usage:
 rename [options] <expression> <replacement> <file>...

Rename files.

Options:
 -v, --verbose       explain what is being done
 -s, --symlink       act on the target of symlinks
 -n, --no-act        do not make any changes
 -o, --no-overwrite  don't overwrite existing files

 -h, --help          display this help
 -V, --version       display version

For more details see rename(1).

有点真相的意思,参数好像变了。我又去看了man的介绍的例子

EXAMPLES         
       Given the files foo1, ..., foo9, foo10, ..., foo278, the commands

           rename foo foo00 foo?
           rename foo foo0 foo??

       will turn them into foo001, ..., foo009, foo010, ..., foo278. And

           rename .htm .html *.htm

       will fix the extension of your html files. Provide an empty
       string for shortening:

           rename '_with_long_name' '' file_with_long_name.*

       will remove the substring in the filenames.

此时此刻,该怎么做一目了然了

rename -v '.bak' '' *.bak

虽然问题解决了,但是想吐槽一下网上的文章,当然也不敢保证各自linux版本的rename对应的版本,还有中文的搜索真的是互相抄袭的实在是太多了,实在是太多的互相爬虫对方,然后获取搜索结果。也许,英文也是这样吧,搜索引擎能否做进一步的优化呢?期待ing

正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2022-08-28发表,共计1537字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码