ITPub博客

首页 > Linux操作系统 > Linux操作系统 > find结合rename实现批量修改后缀

find结合rename实现批量修改后缀

原创 Linux操作系统 作者:diggger 时间:2012-10-30 09:07:45 0 删除 编辑
      记得曾经去腾讯面试运维的职位时,笔试中就有这么道题:要求查找/tmp下以.sh为后缀的文件并将所有这些文件修改为.bash后缀。其实很简单,一个命令可以实现:
# rename .sh .bash *.sh
上面这个命令是将当前目录下的所有.sh文件修改为.bash做后缀。
首先要确保这个命令所在的软件包安装了,
[jeff@rhel55 mydir]$ rpm -qif `which rename`
Name        : util-linux                   Relocations: (not relocatable)
Version     : 2.13                              Vendor: Red Hat, Inc.
Release     : 0.52.el5_4.1                  Build Date: Thu 07 Jan 2010 06:25:25 PM CST
Install Date: Thu 02 Feb 2012 06:49:04 PM CST      Build Host: x86-007.build.bos.redhat.com
Group       : System Environment/Base       Source RPM: util-linux-2.13-0.52.el5_4.1.src.rpm
Size        : 4706614                          License: distributable
Signature   : DSA/SHA1, Wed 13 Jan 2010 05:19:06 PM CST, Key ID 5326810137017186
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Summary     : A collection of basic system utilities.
Description :
The util-linux package contains a large variety of low-level system
utilities that are necessary for a Linux system to function. Among
others, Util-linux contains the fdisk configuration tool and the login
program.
那么配合find就更省事了,
# find /tmp -name "*.sh" -exec rename .sh .bash {} \;
 
 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27795363/viewspace-747867/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-09-13

  • 博文量
    33
  • 访问量
    45476