校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > Shell腳本批量添加擴展名的兩種方法分享

Shell腳本批量添加擴展名的兩種方法分享

熱門標簽:地圖標注超出范圍怎么辦 百度地圖標注圖標更換 百度地圖的地圖標注 excel地址地圖標注 杭州機器人外呼系統 佛山高德地圖標注中心 陜西電銷卡外呼系統怎么安裝 旅游地圖標注大全 東莞電銷機器人價格一覽表

方法1:

復制代碼 代碼如下:

for file in  `ls`; do mv $file $file.txt; done

方法2:

復制代碼 代碼如下:

find . -type f |xargs -i mv {} {}.txt

還有一些試驗不成功的,先記錄在此。

1.用rename命令修改后綴名,這個是最簡單最省事的辦法

復制代碼 代碼如下:

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 00:57 rename1.log

-rw-r–r– 1 root root 0 09-27 00:57 rename2.log

-rw-r–r– 1 root root 0 09-27 00:57 rename3.log

-rw-r–r– 1 root root 0 09-27 00:57 rename4.log

-rw-r–r– 1 root root 0 09-27 00:57 rename5.log

[root@demo test_rename]# rename log txt *.log #把*.log改為*.txt

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 00:57 rename1.txt

-rw-r–r– 1 root root 0 09-27 00:57 rename2.txt

-rw-r–r– 1 root root 0 09-27 00:57 rename3.txt

-rw-r–r– 1 root root 0 09-27 00:57 rename4.txt

-rw-r–r– 1 root root 0 09-27 00:57 rename5.txt

[root@demo test_rename]# 

2.用for、sed和mv修改后綴名

復制代碼 代碼如下:

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 01:51 rename1.log

-rw-r–r– 1 root root 0 09-27 01:21 rename2.log

-rw-r–r– 1 root root 0 09-27 01:21 rename3.log

-rw-r–r– 1 root root 0 09-27 01:21 rename4.log

-rw-r–r– 1 root root 0 09-27 01:21 rename5.log

[root@demo test_rename]# for i in $(ls .)

> do

> mv $i $(echo $i|sed ‘s/\.log/\.txt/')

> done

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 01:51 rename1.txt

-rw-r–r– 1 root root 0 09-27 01:21 rename2.txt

-rw-r–r– 1 root root 0 09-27 01:21 rename3.txt

-rw-r–r– 1 root root 0 09-27 01:21 rename4.txt

-rw-r–r– 1 root root 0 09-27 01:21 rename5.txt

[root@demo test_rename]#

3.用find和xargs添加后綴名

復制代碼 代碼如下:

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 02:20 rename1

-rw-r–r– 1 root root 0 09-27 02:20 rename2

-rw-r–r– 1 root root 0 09-27 02:20 rename3

-rw-r–r– 1 root root 0 09-27 02:20 rename4

-rw-r–r– 1 root root 0 09-27 02:20 rename5

[root@demo test_rename]# find . -type f |xargs -i mv {} {}.txt

[root@demo test_rename]# ll

總計 20

-rw-r–r– 1 root root 0 09-27 02:20 rename1.txt

-rw-r–r– 1 root root 0 09-27 02:20 rename2.txt

-rw-r–r– 1 root root 0 09-27 02:20 rename3.txt

-rw-r–r– 1 root root 0 09-27 02:20 rename4.txt

-rw-r–r– 1 root root 0 09-27 02:20 rename5.txt

[root@demo test_rename]#

標簽:雅安 朝陽 南充 西藏 延邊 隨州 青島 通遼

巨人網絡通訊聲明:本文標題《Shell腳本批量添加擴展名的兩種方法分享》,本文關鍵詞  Shell,腳本,批量,添加,擴展名,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Shell腳本批量添加擴展名的兩種方法分享》相關的同類信息!
  • 本頁收集關于Shell腳本批量添加擴展名的兩種方法分享的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 山阳县| 台江县| 津市市| 临沧市| 西城区| 湟中县| 曲阳县| 牡丹江市| 霍城县| 晋宁县| 呼和浩特市| 许昌市| 庆阳市| 阿鲁科尔沁旗| 阳曲县| 那坡县| 新乡市| 嵊州市| 吕梁市| 永登县| 固原市| 西乌珠穆沁旗| 寿宁县| 石阡县| 棋牌| 大埔县| 巨鹿县| 惠安县| 阿拉善右旗| 新田县| 广南县| 克拉玛依市| 修文县| 湛江市| 沙坪坝区| 大理市| 监利县| 嘉荫县| 三江| 当涂县| 水富县|