Linux Bulk Modified file name

Source: Internet
Author: User

Simulating the creation environment

Need to use \ Escape

[[email protected] ~]# for i in {1..10};d o touch student\_$i\_finshi.jpg;done[[email protected] ~]# LSSTUDENT_10_FINSHI.J PG Student_2_finshi.jpg Student_4_finshi.jpg student_6_finshi.jpg student_8_finshi.jpgstudent_1_finshi.jpg Student_ 3_finshi.jpg student_5_finshi.jpg student_7_finshi.jpg student_9_finshi.jpg

Need to change all student_1_finshi.jsp to student_1.jsp

Method One

idea 1: put LS to see the contents of the variable F, and then echo $f check whether the variable has been saved

[[email protected] ~]# f= ' ls *finshi* ' [[email  Protected] ~]# lsstudent_10_finshi.jpg  student_2_finshi.jpg  student_4_ finshi.jpg  student_6_finshi.jpg  student_8_finshi.jpgstudent_1_finshi.jpg    student_3_finshi.jpg  student_5_finshi.jpg  student_7_finshi.jpg  student_ 9_finshi.jpg[[email protected] ~]# echo  $fstudent _10_finshi.jpg student_1_finshi.jpg  student_2_finshi.jpg student_3_finshi.jpg student_4_finshi.jpg student_5_finshi.jpg  Student_6_finshi.jpg student_7_finshi.jpg student_8_finshi.jpg student_9_finshi.jpg 

idea 2:

[[email protected] ~]# for i in ' ls *finshi* ';d o mv $i ' echo $i |sed ' s#_finshi# #g ';d one [[email protected] ~]# Lsstud Ent_10.jpg student_2.jpg student_4.jpg student_6.jpg student_8.jpgstudent_1.jpg student_3.jpg student_5.jpg Studen T_7.jpg student_9.jpg

Method Two

[[email protected] ~]# lsstudent_10_finshi.jpg  student_2_finshi.jpg   student_4_finshi.jpg  student_6_finshi.jpg  student_8_finshi.jpgstudent_1_finshi.jpg    student_3_finshi.jpg  student_5_finshi.jpg  student_7_finshi.jpg   student_9_finshi.jpg[[email protected] ~]# ls *.jpg|awk -f  ' _finshi '   ' { print  "MV" " " $ " " $1$2} '  mv student_10_finshi.jpg student_10.jpgmv student_ 1_finshi.jpg student_1.jpgmv student_2_finshi.jpg student_2.jpgmv student_3_finshi.jpg  student_3.jpgmv student_4_finshi.jpg student_4.jpgmv student_5_finshi.jpg student_5. jpgmv student_6_finshi.jpg student_6.jpgmv student_7_finshi.jpg student_7.jpgmv  Student_8_finshi.jpg student_8.jpgmv student_9_finshi.jpg student_9.jpg[[email protected]  ~]# ls *.jpg|awk -f  ' _finshi '   ' {print  ' mv '   ' $ '   ' $1$2} ' |bash[[email protected] ~]#  lsstudent_10.jpg  student_2.jpg  student_4.jpg  student_6.jpg   Student_8.jpgstudent_1.jpg   student_3.jpg  student_5.jpg  student_7.jpg   student_9.jpg
Method three (most cattle)

Ideas: using the rename command, replace _finshi with "" to indicate null, then all JPG files

[Email protected] ~]# lsstudent_10_finshi.jpg student_2_finshi.jpg student_4_finshi.jpg student_6_finshi.jpg Student _8_finshi.jpgstudent_1_finshi.jpg student_3_finshi.jpg student_5_finshi.jpg student_7_finshi.jpg student_9_ Finshi.jpg[[email protected] ~]# rename "_finshi" "" *.jpg[[email protected] ~]# lsstudent_10.jpg student_2.jpg Student_ 4.jpg student_6.jpg student_8.jpgstudent_1.jpg student_3.jpg student_5.jpg student_7.jpg student_9.jpg

This article from "Tang Qinglin personal blog" blog, declined reprint!

Linux Bulk Modified file name

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.