Detailed operations on batch file name modification in linux

Source: Internet
Author: User
Article Title: Detailed operations for batch file name modification in linux. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories. In linux, you can modify file names in batches. Recently, you want to add a part of files to the date order. That is, add the current year, month, and day before the file name.
The date format is as follows:
Zianed @ ubuntu :~ /Public_web_sSmO9OUVY1/files/image $ date + % Y % m % d
20091112
1. Use command combinations such as find, awk, grep/sed, and mv to implement
Under Ubuntu
Use the awk command to create an image as follows:
1) Find the file name to be operated
Zianed @ ubuntu :~ /Public_web_sSmO9OUVY1/files/image $ find-name '*. jpg'-printf % fn | grep-v ^ [0-9] | grep-v logo.jpg
Se_platform.jpg
Soa1.jpg
Soa4.jpg
Java_primitive_data_type.jpg
Soa3.jpg
Soa2.jpg
2) extract the file name and keep the file extension unchanged.
Zianed @ ubuntu :~ /Public_web_sSmO9OUVY1/files/image $ find-name '*. jpg '-printf % fn | grep-v ^ [0-9] | grep-v logo.jpg | awk-F '. ''{print $1 }'
Se_platform
Soa1
Soa4
Java_primitive_data_type
Soa3
Soa2
3) replace files in batches
Zianed @ ubuntu :~ /Public_web_sSmO9OUVY1/files/image $ find-name '*. jpg '-printf % f n | grep-v ^ [0-9] | grep-v logo.jpg | awk-F '. ''{print $1} '|
Xargs-I {} mv 00000000.jpg 'date used policyuncdomaind'00000000.jpg
Zianed @ ubuntu :~ /Public_web_sSmO9OUVY1/files/image $ ls
20090818a.jpg 20090919twitter4.jpg
20090818learn.jpg 20091110open_project.jpg
20090819java1.png 20091112java_primitive_data_type.jpg
20090819javaseplatformroadmap.gif 20091112se_platform.jpg
20090916neiji.jpg 20091112soa1.jpg
20090916waiji.jpg 20091112soa2.jpg
20090919photo.jpg 20091112soa3.jpg
20090919twitter.jpg 20091112soa4.jpg
20090919twitter2.jpg logo.jpg
20090919twitter3.jpg

[1] [2] Next page

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.