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
  • 相关阅读:
    IOS:个人笔记|UI_UITableView的优化
    IOS:个人笔记|UI_UITableView
    java基础知识记录(2)
    斐波那契数列
    字符串中数字排序,给定一个字符串“12 33 31 42 ”,或者键盘输入,进行排序
    java基础知识记录(1)
    【Unity】实验二 游戏场景搭建
    Error:java: Compilation failed: internal java compiler error 解决
    Github + Picgo + Typora 让笔记远走高飞
    remote: Incorrect username or password ( access token ) fatal: Authentication failed for
  • 原文地址:https://www.cnblogs.com/l10n/p/9416411.html
Copyright © 2011-2022 走看看