Bash for batch modification of file names (add, remove, modify suffix) _linux shell

Source: Internet
Author: User

First, add suffix

1. Problem: The same directory has a large amount of date-named files, some of which have suffixes, some end with the point, such as 20020101.,20020102.,......,20020101.td,20020102.td ...
Requirements: Add all the suffix to the end of the point. TS
My method:

Copy Code code as follows:

#! /bin/bash
For the files in ' ls *. '
Todo
MV $files ' echo ' $filests '
Done
2. Ibid.
MV $files ${files}ts
3. Ibid.
MV $files ' $files. ts|sed ' s/\.//'
4. File =>file.txt
$files. txt $files MV
5. *.04 => *04.txt
MV $files $ (echo ${files}.txt|sed ' S/\.//1 ')
Or
MV $files ' echo ${files}.txt|sed ' S/\.//1 '

Second, change suffix (. Old =>. New)

Copy Code code as follows:

1. Rename
Rename. old. New *
2.
MV $files ${file%.old}.new
3.
MV $files ' echo $files |tr. New '
4.
MV $files ' echo $files |sed ' s/\.old/\.new/'

Third, go suffix (*.dat => *)

Copy Code code as follows:

1. MV $files ' echo $files |sed ' s/\.dat//'
2. MV $files ' echo $files |tr. DAT (4 spaces) '

Iv. prefix (re* => un*)

Copy Code code as follows:

1. MV $files un${$files #re}
2. MV $files ' echo $files | tr re un '

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.