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.