Bulk Delete file name extensions

Source: Internet
Author: User

The directory has the following two files

1.txt.file Touch 2.txt.file

You want to implement delete. File, which is the extension, can be quickly implemented using the following script

For file in $ (ls *.file);d o ext=${file%.*};mv $file $ext;d One

Where ${file%.*} is to get the file name, Mv$file $ext the rename operation


Add: Echo ${file##*.} Can get the file's extension

Echo ${file%.*} to get the file name

[Email protected] Extension_name$file=1.txt.file

[Email protected] Extension_name$echo ${file%.*} shortest match, get file name
1.txt
[Email protected] Extension_name$echo ${file%%.*}
1

[Email protected] Extension_name$echo ${file##*.} Enable longest match, get extension
File
[Email protected] Extension_name$echo ${file#*.}
Txt.file

Bulk Delete file name extensions

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.