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