Batch renaming Summary

Source: Internet
Author: User

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'

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.