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
  • 相关阅读:
    C# 事件的简单例子
    pl sql 的目录 所在的目录 不能有 小括号,如 Program Files (x86)
    转】 C# 图片格式(JPG,BMP,PNG,GIF)等转换为ICO图标
    TQQ2440第三节:串口
    今天发现一个bug,不知道是什么问题,printf的问题吗,还是什么。先记下!
    【转载】内存对齐详解
    TQQ2440第二节:流水灯
    TQQ2440第一节:启动代码
    wince下sources\sources.cmn\Makefile.def的相关作用
    (基于Java)编写编译器和解释器第10章:类型检查第一部分
  • 原文地址:https://www.cnblogs.com/liang545621/p/9416411.html
Copyright © 2011-2022 走看看