Original Linux under the Rename command __linux

Source: Internet
Author: User

Original paste: Http://www.linuxfly.org/post/300/

5[Rename command under the original]linuxLinuxing, 16:28, Web services» Virtual machines, Comments (0), quotes (0), read (%), Via site OriginalBig |in |SmallReference Address:
Note:This address is only valid dos/windows before 23:59:59 today, the file name is rename. And the book says, Linux under the name of the file or directory to use MV. I have always done so, but ignored the Linux also has a call rename command. are rename, but functionally there is a difference. Rename under Linux is more like a batch renaming tool, which is provided in the Util-linux suite.

first, the basic function
The following information can be found in the man documentation for MV and rename commands:
referencing Mv-move (rename) files
Rename-rename files
In other words, MV can also be used for renaming, but can not achieve batch processing (renamed, do not support * and other symbols), and rename can.
Format used by rename:

$ rename foo foo0 foo?
Rename needs to provide three parameters before the final result can be determined.
Simulate the man document example, the original file:
Reference $ for I in ' seq ';d o touch foo$i;done
$ ls
Foo1 foo18 foo27 foo36 foo45 foo54 foo63 foo72 foo81 foo90
Foo10 foo19 foo28 foo37 foo46 foo55 foo64 foo73 foo82 foo91
foo100 foo2 foo29 foo38 foo47 foo56 foo65 foo74 foo83 foo92
Foo11 foo20 Foo3 foo39 foo48 foo57 foo66 foo75 foo84 foo93
Foo12 foo21 foo30 Foo4 foo49 foo58 foo67 foo76 foo85 foo94
Foo13 foo22 foo31 foo40 foo5 foo59 foo68 foo77 foo86 foo95
Foo14 foo23 foo32 foo41 foo50 foo6 foo69 foo78 foo87 foo96
FOO15 foo24 foo33 foo42 foo51 foo60 foo7 foo79 foo88 foo97
Foo16 foo25 foo34 foo43 foo52 foo61 foo70 foo8 foo89 foo98
Foo17 foo26 foo35 foo44 foo53 foo62 foo71 foo80 foo9 foo99

Renaming result:
(Red is unchanged, blue is part of the change)
Reference $ rename foo foo0 foo?
$ ls
Foo01 foo100 foo20 foo30 foo40 foo50 foo60 foo70 foo80 foo90
Foo02 foo11 foo21 foo31 foo41 foo51 foo61 foo71 foo81 foo91
foo03 foo12 foo22 foo32 foo42 foo52 foo62 foo72 foo82 foo92
foo04 foo13 foo23 foo33 foo43 foo53 foo63 foo73 foo83 foo93
foo05 foo14 foo24 foo34 foo44 foo54 foo64 foo74 foo84 foo94
Foo06 foo15 foo25 foo35 foo45 foo55 foo65 foo75 foo85 foo95
Foo07 foo16 foo26 foo36 foo46 foo56 foo66 foo76 foo86 foo96
foo08 foo17 foo27 foo37 foo47 foo57 foo67 foo77 foo87 foo97
foo09 foo18 foo28 foo38 foo48 foo58 foo68 foo78 foo88 foo98
Foo10 foo19 foo29 foo39 foo49 foo59 foo69 foo79 foo89 foo99
$ rename foo foo0 foo??
$ ls
foo001 foo011 foo021 foo031 foo041 foo051 foo061 foo071 foo081 foo091
foo002 foo012 foo022 foo032 foo042 foo052 foo062 foo072 foo082 foo092
foo003 foo013 foo023 foo033 foo043 foo053 foo063 foo073 foo083 foo093
foo004 foo014 foo024 foo034 foo044 foo054 foo064 foo074 foo084 foo094
foo005 foo015 foo025 foo035 foo045 foo055 foo065 foo075 foo085 foo095
foo006 foo016 foo026 foo036 foo046 foo056 foo066 foo076 foo086 foo096
foo007 foo017 foo027 foo037 foo047 foo057 foo067 foo077 foo087 foo097
foo008 foo018 foo028 foo038 foo048 foo058 foo068 foo078 foo088 foo098
foo009 foo019 foo029 foo039 foo049 foo059 foo069 foo079 foo089 foo099
foo010 foo020 foo030 foo040 foo050 foo060 foo070 foo080 foo090 foo100
This example gives the use of two types of file batch renaming:
Reference first argument: replaced string
Second argument: replaced by a string
Third parameter: matches the file mode to be replaced
Rename support wildcard characters, the basic wildcard characters are as follows:
Reference? Can replace a single character
* Can replace multiple characters
[CharSet] can override any single character in the CharSet set
Ii. Other examples
Look at the role of *:
Reference $ rm-f *
$ for I in ' seq ';d o touch foo$i;done
$ rename Foo foo0 foo*
$ ls
Foo01 foo018 foo027 foo036 foo045 foo054 foo063 foo072 foo081 foo090
foo010 foo019 foo028 foo037 foo046 foo055 foo064 foo073 foo082 foo091
foo0100 foo02 foo029 foo038 foo047 foo056 foo065 foo074 foo083 foo092
foo011 foo020 foo03 foo039 foo048 foo057 foo066 foo075 foo084 foo093
foo012 foo021 foo030 foo04 foo049 foo058 foo067 foo076 foo085 foo094
foo013 foo022 foo031 foo040 foo05 foo059 foo068 foo077 foo086 foo095
foo014 foo023 foo032 foo041 foo050 foo06 foo069 foo078 foo087 foo096
foo015 foo024 foo033 foo042 foo051 foo060 foo07 foo079 foo088 foo097
foo016 foo025 foo034 foo043 foo052 foo061 foo070 foo08 foo089 foo098
foo017 foo026 foo035 foo044 foo053 foo062 foo071 foo080 foo09 foo099
And look at the role of [CharSet]:
Reference $ rm-f *
$ for I in ' seq ';d o touch foo$i;done
$ rename Foo foo0 foo[9]*
$ ls
foo09 foo099 foo17 foo26 foo35 foo44 foo53 foo62 foo71 foo80
foo090 foo1 foo18 foo27 foo36 foo45 foo54 foo63 foo72 foo81
foo091 foo10 foo19 foo28 foo37 foo46 foo55 foo64 foo73 foo82
foo092 foo100 foo2 foo29 foo38 foo47 foo56 foo65 foo74 foo83
foo093 foo11 foo20 foo3 foo39 foo48 foo57 foo66 foo75 foo84
foo094 foo12 foo21 foo30 foo4 foo49 foo58 foo67 foo76 foo85
foo095 foo13 foo22 foo31 foo40 foo5 foo59 foo68 foo77 foo86
foo096 foo14 foo23 foo32 foo41 foo50 foo6 foo69 foo78 foo87
foo097 foo15 foo24 foo33 foo42 foo51 foo60 foo7 foo79 foo88
foo098 foo16 foo25 foo34 foo43 foo52 foo61 foo70 foo8 foo89
It is not difficult to understand, look for the environment test will understand. Rename can be used to reduce the part of the write for loop work, or more convenient. Tags:rename, MV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.