zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    JDK环境变量设置
    用mapXtreme Java开发web gis应用 (下)
    最简单的mapxtreme的servlet例子
    MapXtreme Java开发环境配置
    MapXtreme2004代码 读取TAB表中的元素
    一段旋转图元几何体的代码
    oracle ocp题库变化,052最新考试题及答案整理30
    OCP认证052考试,新加的考试题还有答案整理23题
    OCP题库变了,2018年052新题库29题
    2018OCP最新题库052新加考题及答案整理27
  • 原文地址:https://www.cnblogs.com/l10n/p/9416411.html
Copyright © 2011-2022 走看看