Shell script 3 Implementations of batch renaming file suffixes _linux shell

Source: Internet
Author: User

Today suddenly think of a problem has not hands-on practice, is the use of Shell batch modification file suffix, now hands-on practice.

Requirements: The home directory has some SQL files, want to bulk renamed into TXT

1, find + xargs +sed

Copy Code code as follows:

Find/root-name ' *.sql ' |xargs-i echo {} {} |sed ' S/sql/txt/2′|xargs mv

find/root/-name ' *.sql ' |sed-e ' s/\ (. *\). SQL$/MV & \1.txt/e '//b Brother offers


If you refer to Brother B, you can also write an awk version of:
Copy Code code as follows:

find/root/-name ' *.sql ' |awk ' a=$0;sub (/sql$/, "TXT", $); print "MV", a,$0} ' |bash

find/root/-maxdepth 1-name ' *.sql ' |awk ' {a=$0;sub (/txt$/, "SQL", $); System ("MV" "" A "" $)} "


2, for Loop
Copy Code code as follows:

For SQL in ' Find/root-name ' *.sql ';d o mv $sql ' echo $sql |sed ' s/sql/txt/';d one

3, rename
Copy Code code as follows:

Rename. sql. txt *.sql//seems unable to recursively catalog

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.