Http://bbs.chinaunix.net/thread-554405-1-1.html
Thanks to the attention of various experts from Cu, We have summarized the methods for renaming the files we have collected and sorted in batches as follows, which are also referenced by original creators and will not be specified in reference. During the study and research, I often encountered the renaming of batch files, so I made up my mind to solve this problem once and for all. If this is not correct, please let us know. Thank you for your comments and supplements!
A and suffix
1. problem: a directory contains a large number of files named by date, some of which have suffixes and some end with dots, such as 20020101., 20020102 .,......, 20020101. TD, 20020102.td.pdf ......
Requirement: add the suffix. Ts to all vertices.
My method:
#! /Bin/bash
For files in 'ls *.'
Do
MV $ files 'echo "$ filests "'
Done
2. Same as above
MV $ files $ {files} TS
3. Same as above
MV $ files '$ files. Ts | SED's /\.//''
4. File => file.txt
MV $ files saved files.txt
5. *. 04 => * 04.txt
MV $ files $ (echo audio files.txt | SED's/\. // 1 ')
Or
MV $ files 'echo too many files0000.txt | SED's/\. // 1''
B. Change the suffix (. Old =>. New)
1. Rename
Rename. Old. New *
2.
MV $ files $ {file %. Old}. New
3.
MV $ files 'echo $ files | tr. Old. new'
4.
MV $ files 'echo $ files | SED's/\. Old/\. New /''
C remove the suffix (*. dat => *)
1. Mv $ files 'echo $ files | SED's/\. dat //''
2. Mv $ files 'echo $ files | tr. dat (4 spaces )'
D. Change the prefix (Re * => UN *)
1. Mv $ files UN $ {$ files # re}
2. Mv $ files 'echo $ files | tr re UN'