Script for Shell script to bulk modify file name suffix

Source: Internet
Author: User
Experimental material:
[[email protected] test]# ls//This directory contains all the files ending in. txt and requires all to be replaced by the. Doc End
1.txt 2.txt 3.txt 4.txt 5.txt

Writing scripts
[Email protected] test]# vim/root/25.sh

Script content:
#!/bin/bash

For I ls * .$1 in//defines the range of values for I, as long as the files ending in the file are displayed (enclosed in ls * .$1 anti-quotation marks, I don't know what the reason is, the anti-quotes are not visible)
Do
MV $i ${i%.}. $ &>/dev/null//On I perform a de-tail operation, plus a new file suffix, i%. Specify the file name of I from the. Start to remove the trailing inclusions.
Done

Give Execute permission
[Email protected] test]# chmod +x/root/25.sh

Test script:
[[email protected] test]#/root/25.sh txt doc
[[email protected] test]# ls
1.doc 2.doc 3.doc 4.doc 5.doc

Script for Shell script to bulk modify file name suffix

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.