zoukankan      html  css  js  c++  java
  • linux系统中批量对一类文件重命名

    1、rename命令

    [root@centos79 test]# ls
    a.mp4  dup1.mp4  dup2.mp4  dup4.mp4
    [root@centos79 test]# rename mp4 txt *.mp4
    [root@centos79 test]# ls
    a.txt  dup1.txt  dup2.txt  dup4.txt

    2、利用循环语句

    [root@centos79 test]# ls
    a.txt  dup1.txt  dup2.txt  dup4.txt
    [root@centos79 test]# n=1; for file in *.txt; do num=$(printf "%02d" $n); mv $file new$num.mp3; let n=n+1;done
    [root@centos79 test]# ls
    new01.mp3  new02.mp3  new03.mp3  new04.mp3

    3、实现按照文件大小递增命名

    [root@centos79 test]# ls
    a.txt  b.txt  c.txt  d.txt
    [root@centos79 test]# ll -h
    total 170M
    -rw-r--r--. 1 root root 50M Jul  6 19:21 a.txt
    -rw-r--r--. 1 root root 10M Jul  6 19:21 b.txt
    -rw-r--r--. 1 root root 80M Jul  6 19:21 c.txt
    -rw-r--r--. 1 root root 30M Jul  6 19:21 d.txt
    [root@centos79 test]# a=$(ls -S | xargs du -sh | tac | cut -f 2)
    [root@centos79 test]# echo $a
    b.txt d.txt a.txt c.txt
    [root@centos79 test]# n=1; for file in $a; do num=$(printf "%02d" $n); mv $file $num.txt; let n=n+1; done
    [root@centos79 test]# ls
    01.txt  02.txt  03.txt  04.txt
    [root@centos79 test]# ll -h
    total 170M
    -rw-r--r--. 1 root root 10M Jul  6 19:21 01.txt
    -rw-r--r--. 1 root root 30M Jul  6 19:21 02.txt
    -rw-r--r--. 1 root root 50M Jul  6 19:21 03.txt
    -rw-r--r--. 1 root root 80M Jul  6 19:21 04.txt
  • 相关阅读:
    杭电1058
    动态规划之背包模版
    按字典序依次打印只由1~n组成的n位数
    杭电1029
    杭电1257
    杭电2191
    杭电1114
    杭电2602
    南阳975
    杭电2138
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14974081.html
Copyright © 2011-2022 走看看