• 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
  • 相关阅读:
    爱因斯坦谜题的真正答案
    Lucence 中的排序算法解析
    XML 解析中,如何排除控制字符
    如何在百度贴吧里加入自己的广告图片
    ASP.NET 不能调试的几种情况
    Zend_Search_Lucence 中用UTF8 编码建立索引的问题
    c++继承中的内存布局 <转>
    Effective C++ 学习笔记(20)
    Effective C++ 学习笔记(19)
    Effective C++ 学习笔记(17)
  • 原文地址:https://www.cnblogs.com/l10n/p/9416411.html
Copyright © 2020-2023  润新知