日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 批量更改文件名后缀,批量修改文件名及扩展名

發布時間:2024/3/24 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 批量更改文件名后缀,批量修改文件名及扩展名 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.變量基礎知識

${var}????????變量var的值,?與$var相同

${var-DEFAULT}如果var沒有被聲明,?那么就以$DEFAULT作為其值?*

${var:-DEFAULT}如果var沒有被聲明,?或者其值為空,?那么就以$DEFAULT作為其值?*

${var=DEFAULT}如果var沒有被聲明,?那么就以$DEFAULT作為其值?*

${var:=DEFAULT}如果var沒有被聲明,?或者其值為空,?那么就以$DEFAULT作為其值?*

${var+OTHER}如果var聲明了,?那么其值就是$OTHER,?否則就為null字符串

${var:+OTHER}如果var被設置了,?那么其值就是$OTHER,?否則就為null字符串

${var?ERR_MSG}如果var沒被聲明,?那么就打印$ERR_MSG?*

${var:?ERR_MSG}如果var沒被設置,?那么就打印$ERR_MSG?*

${!varprefix*}匹配之前所有以varprefix開頭進行聲明的變量

${!varprefix@}匹配之前所有以varprefix開頭進行聲明的變量

#!/bin/bash

#

#

#定義path變量

path?=?/data/back/

#搜索path路徑下包含tar.gz的文件并刪除

find?$path?-name?"*.tar.gz"?-type?f?|xagrs?rm?-f

#優化之后

find?${path:=/data/back/}?-name?"*.tar.gz"?-type?f?|xagrs?rm?-f

#此方式path變量沒有賦值的情況,有賦值使用賦值,沒有賦值使用=號后面的值

#此方式主要針對刪除操作

2.變量子串知識

${#string}????????????????????????$string的長度

${string:position}????????????????在$string中,?從位置$position開始提取子串

${string:position:length}????????在$string中,?從位置$position開始提取長度為$length的子串

${string#substring}????????????????從變量$string的開頭,?刪除最短匹配$substring的子串

${string##substring}????????????????從變量$string的開頭,?刪除最長匹配$substring的子串

${string%substring}????????????????從變量$string的結尾,?刪除最短匹配$substring的子串

${string%%substring}????????????????從變量$string的結尾,?刪除最長匹配$substring的子串

${string/substring/replacement}????????使用$replacement,?來代替第一個匹配的$substring

${string//substring/replacement}使用$replacement,?代替所有匹配的$substring

${string/#substring/replacement}如果$string的前綴匹配$substring,?那么就用$replacement來代替匹配到的$substring

${string/%substring/replacement}如果$string的后綴匹配$substring,?那么就用$replacement來代替匹配到的$substring

批量修改文件名

-rw-r--r--?1?root?root?0?Dec??1?00:10?eddy_10299_1_finished.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:10?eddy_10299_2_finished.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:10?eddy_10299_3_finished.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:10?eddy_10299_4_finished.jpg

#!/bin/bash

#?author:eddy?date:2015-11-30

#?rename?file

#?v1.0

for??i?in?`ls?temp/*.jpg`

do

mv?$i?`echo?${i%_finished*}.jpg`

done

以上方式偏于復雜及不好理解

使用linux自帶的rename命令進行批量重命名

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_10.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_1.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_2.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_3.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_4.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_5.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_6.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_7.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_8.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?eddy_9.txt

[root@eddy?temp]#?rename?"eddy"?"yys"?eddy_*

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_10.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_1.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_2.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_3.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_4.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_5.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_6.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_7.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_8.txt

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_9.txt

批量修改擴展名

依然可以用rename實現

[root@eddy?temp]#?rename?"txt"?"jpg"?yys_*

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_10.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_1.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_2.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_3.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_4.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_5.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_6.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_7.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_8.jpg

-rw-r--r--?1?root?root?0?Dec??1?00:33?yys_9.jpg

總結

以上是生活随笔為你收集整理的linux 批量更改文件名后缀,批量修改文件名及扩展名的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。