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

记得曾经去腾讯面试运维的职位时,笔试中就有这么道题:要求查找/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 CSTInstall Date: Thu 02 Feb 2012 06:49:04 PM CST Build Host: x86-007.build.bos.RedHat.comGroup : System Environment/Base Source RPM: util-linux-2.13-0.52.el5_4.1.src.rpmSize : 4706614 License: distributableSignature : DSA/SHA1, Wed 13 Jan 2010 05:19:06 PM CST, Key ID 5326810137017186Packager : Red Hat, Inc. <>Summary : A collection of basic system utilities.Description :The util-linux package contains a large variety of low-level systemutilities that are necessary for a Linux system to function. Amongothers, Util-linux contains the fdisk configuration tool and the loginprogram.

那么配合find就更省事了,

# find /tmp -name “*.sh” -exec rename .sh .bash {} \;

,困难是人的教科书。

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

相关文章:

你感兴趣的文章:

标签云: