Linux rename files or folders (MV Command rename command) __linux

Source: Internet
Author: User
Turn from: http://www.cnblogs.com/yes123/p/3919337.html


Renaming a file or directory under Linux allows you to use either the MV command or the rename command, where you can share the two methods.



The MV command can be renamed and can move files or folders.



Example: Rename directory A to B
MV A B



Example: Move the/a directory down to/b, and rename to C
mv/a/b/c



In fact, to rename a file or directory in text mode, you only need to use the MV command, for example, to rename a file named ABC to 1234:
MV ABC 1234



Note that if there is a 1234 file in the current directory, the file will overwrite it.



The following describes the use of another rename command rename command in a Linux system. Related reading: Introduction to Linux Rename command usage find command and rename batch modify filename suffix Linux rename command batch rename instance tutorial



Create a batch of file names that are similar in size. "The first step in testing"


[Root@jbxue net]# for I in ' seq-w ' > doing touch
stu\_$i\_linux.jpg
> Done
[root@jbxue net]# sl
Tot Al 0
-rw-r--r--1 root 0 Oct 9 21:22 stu_01_linux.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_02_linux.jpg-rw-r--r--1 Root 0 Oct 9 21:22 stu_03_linux.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_04_linux.jpg-RW
-r--r--1 Root 0 Oct 9 21:22 stu_05_linux.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_06_linux.jpg-rw-r--r
--1 Root 0 Oct 9 21:22 stu_07_linux.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_08_linux.jpg
-rw-r--r--1 Root root 0 Oct 9 21:22 stu_09_linux.jpg
-rw-r--r--1 Root 0 Oct 9 21:22 stu_10_linux.jpg


Then, use Rename to make modifications


[Root@jbxue net]# rename \_linux ' *.jpg
[root@jbxue net]# SL Total
0
-rw-r--r--1 root 0 Oct 9 21:22 St U_01.jpg
-rw-r--r--1 Root 0 Oct 9 21:22 stu_02.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_03.jpg-rw-r
--r--1 Root 0 Oct 9 21:22 stu_04.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_05.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_06.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_07.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_ 08.jpg
-rw-r--r--1 Root 0 Oct 9 21:22 stu_09.jpg
-rw-r--r--1 root root 0 Oct 9 21:22 stu_10.jpg


Note that if you want to replace the underline, you cannot add any quotes.



To create some test files:


[root@jbxue net]# for i in `seq -w 10`; do touch stu\_$i\_linux.jpg; done
[root@jbxue net]# sl
total 0
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_01_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_02_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_03_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_04_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_05_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_06_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_07_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_08_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_09_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:58 stu_10_linux.jpg
[root@jbxue net]# rename '\_linux' '' *.jpg
[root@jbxue net]# sl
total 0
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_01_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_02_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_03_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_04_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_05_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_06_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_07_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_08_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_09_linux.jpg
-rw-r--r-- 1 root root 0 Oct 9 21:27 stu_10_linux.jpg


Rename version If it is a Perl version, the Rename command supports regular; therefore, under the Perl version of Rename, execution of the above command succeeds, and if the rename version is version c, the command is unsuccessful.



This is a version support issue, so don't delve into it. For a comparison of two versions, please refer to the detailed description of the Rename command batch rename under Linux.



The previous problem may have been caused by the fact that his rename version does not support it. So, the emphasis here is rename, although this command is not very important. But it's actually very useful, isn't it.



Of course, some people will say, you are in a directory, then I would be in a different directory.
With two commands. A find first to modify the file found out, and then a pipeline, a rename is not finished.
Yes, the above method can be said to be a kind of thinking, in fact there are many kinds of ideas.



Attached, view the rename version of the information


[Root@jbxue net]# man Rename | Head-1
RENAME (1) Linux programmer ' s Manual RENAME (1)
Related Article

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.