Linux (Uinx) bulk Modify the file name of the command line

Source: Internet
Author: User
Tags uppercase letter

Ming content before: Colleagues have a batch to change the file name on the server needs. I gave him the command to batch modify the file name on Ubuntu, but I couldn't use it. Because the server is UNIX. So let's tidy up the commands for batch modification of file names.

=================================================== I am the delimiter ================================================

First you need to know where you are in the server environment.

Command: Cat/proc/version

The next step is to introduce an Ubuntu batch change file name command.

Command: LS

Let's take a look at what files are under the folder

Then say GG in the file name changed to YY

Command: Rename-v ' s/gg/yy ' *

Then command: LS, look at the name now.

Explain this command:

Rename-v ' s/gg/yy ' *

=================================================== I am the delimiter ================================================

When you don't know how to use a command, you can hit this command at the command line.

Command: Man rename

The Man command is a help instruction under Linux, which allows you to view information such as instruction help, configuration file Help, and programming help in Linux.

PS: Click Q to exit.

I am the delimiter ************************************* ***********************************************************

But the above command is not for UNIX.

Same command, man rename.

displayed on the Uinx as:

This means that in this environment, there is no way to bulk modify the file name using the method above. At this point, we need to rename it with a For loop.

Command: For i in ' ls '; Do mv-f $i ' echo ' 6 "$i"; Done

Explanation:for i in ' ls ' means to loop all files under the current folder;

Do mv-f execute MV command,-F: If the target file or directory is duplicated with an existing file or directory, overwrite the existing file or directory directly;

$i represents each of the files in the loop body;

The echo output is xxx, and if all the files under the folder are renamed, then the previous commands can be copied and pasted, and you can change from echo to the way you want them.

   "6" $i ' in front of all filenames plus 6;

done finished;

The result of the command runs as follows:

Here's a few??, better understand the point.

Command: For i in ' ls '; Do mv-f $i ' echo $i | Sed ' s/^.//'; Done

Note: SED can process and edit text files according to script instructions. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on.

followed by a regular expression,/^ represents the beginning of a regular,. represents the first bit,/ indicates the end. The meaning is to place the first bit empty.

Command: For i in ' ls '; Do mv-f $i ' echo $i | Sed ' s/^./new/'; Done changes the first bit of the file name to new.

Command: For i in ' ls '; Do mv-f $i ' echo $i | Sed ' s/^/new/'; Done add new in front of the file name.

Command: For i in ' ls '; Do mv-f $i ' echo $i | Sed ' s/$/new/'; Done adds new after the file name.

Command: For i in ' ls '; Do mv-f $i ' echo $i | Sed ' s/.$/6/'; Done adds new after the file name.

Command: For i in ' ls '; Do mv-f $i ' echo $i | TR A-Z '; Done converts the uppercase letter of the file name to lowercase letters;

=================================================== delimiter ========================================================= =================

I hope late will say such sweet words to me one day. Mua

Linux (Uinx) bulk Modify the file name of the command line

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.