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