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
  • 相关阅读:
    bootstrap基础(四)
    bootstrap基础(三)
    bootstrap基础(二)
    python @staticmethod和@classmethod
    python的数据类型可变不可变
    json.dumps()和json.loads()和eval()
    Linux如何查看端口状态
    python 同时遍历两个list
    dogedoge浏览器爬取标题
    虚拟机数据库连接Windows本地数据库
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14974081.html
Copyright © 2011-2022 走看看