Batch renaming with Shell

Source: Internet
Author: User

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

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.