记得曾经去腾讯面试运维的职位时,笔试中就有这么道题:要求查找/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. <>
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 {} \;