shell批量修改后缀_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 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 {} \;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值