Batch Create files first
#!/bin/shif [!-d/tmp/Chenyao]then mkdir /tmp/chenyao-p fi /tmp/Chenyao for in {1.. Ten }do touch chenyao-$i. html done
Batch Renaming
[Email Protected]amp scripts]# cd/tmp/chenyao/[email protected] chenyao]#pwd/tmp/Chenyao[[email protected] chenyao]# ll Total0-rw-r--r--1Root root0Nov at A: thechenyao-1. html-rw-r--r--1Root root0Nov at A: thechenyao-Ten. html-rw-r--r--1Root root0Nov at A: thechenyao-2. html-rw-r--r--1Root root0Nov at A: thechenyao-3. html-rw-r--r--1Root root0Nov at A: thechenyao-4. html-rw-r--r--1Root root0Nov at A: thechenyao-5. html-rw-r--r--1Root root0Nov at A: thechenyao-6. html-rw-r--r--1Root root0Nov at A: thechenyao-7. html-rw-r--r--1Root root0Nov at A: thechenyao-8. html-rw-r--r--1Root root0Nov at A: thechenyao-9. Html[[email protected] chenyao]# F=chenyao-1. Html[[email protected] chenyao]#Echo$fchenyao-1. Html[[email protected] chenyao]#Echo$f |sed 's#chenyao\ (. *\) html#linux\1php#g'Linux-1. Php[[email protected] chenyao]#MV$f 'Echo$f |sed 's#chenyao\ (. *\) html#linux\1php#g'' //execute the command test on the command line first, then copy it to the script after success, so insurance, this is thought [[email protected] chenyao]# lltotal0-rw-r--r--1Root root0Nov at A: thechenyao-Ten. html-rw-r--r--1Root root0Nov at A: thechenyao-2. html-rw-r--r--1Root root0Nov at A: thechenyao-3. html-rw-r--r--1Root root0Nov at A: thechenyao-4. html-rw-r--r--1Root root0Nov at A: thechenyao-5. html-rw-r--r--1Root root0Nov at A: thechenyao-6. html-rw-r--r--1Root root0Nov at A: thechenyao-7. html-rw-r--r--1Root root0Nov at A: thechenyao-8. html-rw-r--r--1Root root0Nov at A: thechenyao-9. html-rw-r--r--1Root root0Nov at A: thelinux-1. Php[[email protected] chenyao]# vim piliang2.SH//write a script to implement batch renaming#!/bin/SHCD/tmp/Chenyao forFinch`ls/tmp/chenyao/` Do MV$f 'Echo$f |sed 's#chenyao\ (. *\) html#linux\1php#g'' &>/dev/NULL Done[email protected] scripts]#SHPiliang2.SH[email protected] scripts]# ll/tmp/chenyao///You can see that you have successfully renamed Total0-rw-r--r--1Root root0Nov at A: thelinux-1. PHP-rw-r--r--1Root root0Nov at A: thelinux-Ten. PHP-rw-r--r--1Root root0Nov at A: thelinux-2. PHP-rw-r--r--1Root root0Nov at A: thelinux-3. PHP-rw-r--r--1Root root0Nov at A: thelinux-4. PHP-rw-r--r--1Root root0Nov at A: thelinux-5. PHP-rw-r--r--1Root root0Nov at A: thelinux-6. PHP-rw-r--r--1Root root0Nov at A: thelinux-7. PHP-rw-r--r--1Root root0Nov at A: thelinux-8. PHP-rw-r--r--1Root root0Nov at A: thelinux-9. Php[[email protected] scripts]#
Old boy's blog: Batch renaming
http://oldboy.blog.51cto.com/2561410/711342
Batch renaming with Shell