linux的rename命令

來源:互聯網
上載者:User

不同於Dos下的rename命令,linux下的rename命令功能非常強大。

#man rename

NAME
       rename - Rename files

SYNOPSIS
       rename from
to
file...

DESCRIPTION
       rename will rename the specified files by replacing the first occurrence of from in their name by to.

       For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands

              rename foo foo0 foo?
              rename foo foo0 foo??

       will turn them into foo001, ..., foo009, foo010, ..., foo278.

       And
              rename .htm .html *.htm

       will fix the extension of your html files.

從上面可以看到:

1. rename命令是三個參數

2. rename命令支援萬用字元進行批量重新命名

3. rename命令會不會支援Regex

rename的參數


 

rename命令的格式:
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

第一個參數:被替換掉的字串
第二個參數:替換成的字串
第三個參數:匹配要替換的檔案模式

eg:rename  main1.c main.c main1.c  將main1.c重新命名為main.c

rename支援萬用字元

?    可替代單個字元
*    可替代多個字元
[charset]    可替代charset集中的任意單個字元

eg:檔案夾中有這些檔案foo1, ..., foo9, foo10, ..., foo278,

如果使用      rename foo foo0 foo?

會把foo1到foo9的檔案重新命名為foo01到foo09,重新命名的檔案只是有4個字元長度名稱的檔案,檔案名稱中的foo被替換為foo0。

如果使用
      rename foo foo0 foo??

foo01到foo99的所有檔案都被重新命名為foo001到foo099,只重新命名5個字元長度名稱的檔案,檔案名稱中的foo被替換為foo0。

如果使用
      rename foo foo0 foo*

foo001到foo278的所有檔案都被重新命名為foo0001到foo0278,所有以foo開頭的檔案都被重新命名。

如果使用
     

 rename foo0 foo foo0[2]*

從foo0200到foo0278的所有檔案都被重新命名為foo200到foo278,檔案名稱中的foo0被替換為foo。

rename支援Regex






 

eg:

字母的替換rename "s/AA/aa/" *             //把檔案名稱中的AA替換成aa
修改檔案的尾碼rename "s//.html//.php/" *     //把.html 尾碼的改成 .php尾碼
大量新增檔案尾碼rename "s/$//.txt/" *             //把所有的檔案名稱都以txt結尾
大量刪除檔案名稱rename "s//.txt//" *               //把所有以.txt結尾的檔案名稱的.txt刪掉

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.