#脚本#Linux 批量整理(重命名)文件
主机社 1月前

用法:
    rnall.sh [文件名后缀] [文件名头部(可选)]

注意: 
     假如文件有8个,则格式为[08],第一个为[01];
     假如文件有88个,则格式为[88],第一个为[01];
     假如文件有888个,则格式为[888],第一个为[001];
     假如文件有8888个,则格式为[8888],第一个为[0001];
     最大支持9999个文件重名命,如果需要更多,自己改吧。

用法:

rnall.sh -t [文件名后缀,文件名后缀] -h [文件名头部(可选)] -r [递归模式] -s [显示错误信息]

示例:

将该目录下所有的以jpg和png为后缀的文件,重新排序;

并添加  MoeClub.org   为前缀.

rnall -t jpg,png -h MoeClub.org

提示:

复制到 /usr/local/bin 文件夹中,命名为rnall,并赋予a+x权限;

就可直接调用此命令,方便使用。

你可以参考使用这个命令:

chmod a+x /usr/local/bin/rnall

下载地址:

wget --no-check-certificate -qO /usr/local/bin/rnall 'https://moeclub.org/attachment/LinuxShell/rnall.sh' && chmod a+x /usr/local/bin/rnall

具体用法请查看这篇文章:

https://moeclub.org/2017/03/24/80/


附上完整代码:

#rnall.sh

#!/bin/bashType="$1";Head="${2:-}";ls -1 *.$Type >/dev/null 2>&1[ $? -ne '0' ] && echo "Not found *.$Type in this directory! " && exit 1Num="$(ls -1 *.$Type |wc -l)"[ $Num -lt '100' ] && NUM=2;[ $Num -ge '100' ] && [ $Num -lt '1000' ] && NUM=3;[ $Num -ge '1000' ] && [ $Num -lt '10000' ] && NUM=4;[ -n "$Head" ] && Head="$Head-"i=1for var in `ls -1 *.$Type` do  [ -z "$NUM" ] && echo "Error ! "&& break;  [ $NUM -eq '2' ] && [ $i -lt '10' ] && mv -f "$var" "$Head[0$i].$Type";  [ $NUM -eq '2' ] && [ $i -ge '10' ] && mv -f "$var" "$Head[$i].$Type";  [ $NUM -eq '3' ] && [ $i -lt '10' ] && mv -f "$var" "$Head[00$i].$Type";  [ $NUM -eq '3' ] && [ $i -ge '10' ] && [ $i -lt '100' ] && mv -f "$var" "$Head[0$i].$Type";  [ $NUM -eq '3' ] && [ $i -ge '100' ] && [ $i -lt '1000' ] && mv -f "$var" "$Head[$i].$Type";  [ $NUM -eq '4' ] && [ $i -lt '10' ] && mv -f "$var" "$Head[000$i].$Type";  [ $NUM -eq '4' ] && [ $i -ge '10' ] && [ $i -lt '100' ] && mv -f "$var" "$Head[00$i].$Type";  [ $NUM -eq '4' ] && [ $i -ge '100' ] && [ $i -lt '1000' ] && mv -f "$var" "$Head[0$i].$Type";  [ $NUM -eq '4' ] && [ $i -ge '1000' ] && [ $i -lt '10000' ] && mv -f "$var" "$Head[$i].$Type";  [ -n "$NUM" ] && i=$[$i+1];done

作者:Vicer

支持作者:https://moeclub.org/

查看原帖:https://www.hostloc.com/thread-357643-1-1.html

最新回复 (0)
返回
网站标签