• rename


    功能说明:rename命令通过字符串替换的方式批量修改文件名。
     
    语法格式: rename from to file
    from:代表需要替换或者需要处理的字符(一般是文件名的一部分,也包括扩展名)。
    to:把前面的from代表的内容替换为to代表的内容。
    file:待处理的文件,可以用 “*”通配所有文件。
     
    范例1.批量修改文件名案例
    首先创建测试文件
    [root@restoredb temp]# for i in `seq -w 10`;do touch head\_$i\_test.txt;done
    [root@restoredb temp]# ll
    total 0
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_01_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_02_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_03_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_04_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_05_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_06_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_07_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_08_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_09_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_10_test.txt
     
    将所有的 _test 替换为空。
    [root@restoredb temp]# rename "_test" "" * 
    [root@restoredb temp]# ll
    total 0
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_01.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_02.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_03.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_04.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_05.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_06.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_07.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_08.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_09.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:15 head_10.txt
     
    范例2.批量修改扩展名案例
    首先创建测试文件
    [root@restoredb temp]# for i in `seq -w 10`;do touch head\_$i\_test.txt;done
    [root@restoredb temp]# ll
    total 0
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_01_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_02_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_03_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_04_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_05_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_06_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_07_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_08_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_09_test.txt
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_10_test.txt
     
    将所有文件的.txt 替换为.log 
    [root@restoredb temp]# rename .txt .log *.txt
    [root@restoredb temp]# ll
    total 0
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_01_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_02_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_03_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_04_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_05_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_06_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_07_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_08_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_09_test.log
    -rw-r--r-- 1 root root 0 Jul 17 23:17 head_10_test.log
  • 相关阅读:
    java 接口和抽象类的一个最大的区别
    python 简化数据结构的初始化二 支持关键字参数
    python 简化数据结构的初始化一
    python @staticmethod
    python @classmethod
    codeskulptor hosts
    An Introduction to Interactive Programming in Python (Part 1) -- Week 2_2 练习
    An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习
    mysql-5.7.14-winx64免安装版在win10下的详细配置过程
    python 反模式
  • 原文地址:https://www.cnblogs.com/liang545621/p/9416411.html
Copyright © 2020-2023  润新知