Shell batch rename

Source: Internet
Author: User

I. Practice

In the current directory, You need to rename all the files in the format of school1, school2 ...... And so on

 
#! /Bin/bash

Echo hello;

 

 
A =1;
ForI in *;
DoEcho$ I;
MV$ I "School $";
A = $ (($+1));#A = 'expr $ A + 1' doesn't seem to work. Add a space !! #A = 'expr $ A + 1'
 
Done

Ii. Small exercises

Batch rename some files. These files have common features, such as having the same letters or having no common features. You want to rename them and modify the characters at the same position. 1. I want to change the first letter of their names to "Q", and the others will not change. For I in 'LS'; Do MV-F $ I 'echo $ I | SED's/^. /Q/''; done or write a script to make it clearer: For file in 'LS'
Do
Newfile = 'echo $ I | SED's/^./Q /''
MV $ File $ newfile
Done 2. Change the first five letters to zhaozh. For I in 'LS'; Do MV-F $ I 'echo $ I | SED's/^.../zhaozh/''; done 3. Change the last five letters to "Snail Il ". For I in 'LS'; Do MV-F $ I 'echo $ I | SED's/... $/snail il/''; done 4. Add _ Hoho _ For I in 'LS'; Do MV-F $ I 'echo "_ Hoho _" $ I '; done 5. Change all lowercase letters to uppercase letters. For I in 'LS'; Do MV-F $ I 'echo $ I | tr a-Z A-Z '; done Five examples are given. In the end, the idea of "for loop + combined command processing" is used to batch rename objects.

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.