I have some files which was written as : test_026542_time0663550.5.jpeg and I would like to rename as test_0663550.jpeg in order to classify easily by order number because I have some errors with the current names.
Asked
Active
Viewed 88 times
0
muru
- 207,228
user3601754
- 173
2 Answers
0
Use the rename function. It's basic(prototype form) is $ rename s/"SEARCH"/"REPLACE"/g *. This replaces the file "SEARCH" with "REPLACE". The /g means global, so if you had a "SEARCH SEARCH.jpg", it would be renamed "REPLACE REPLACE.jpg". The * is the extension type like .mp3 or .pdf. So, your example would be:
$ rename s/'test_026542_time0663550.5.jpeg'/'test_0663550_.jpeg'/g *
This should help.
Tony Lancer
- 1,003
0
My battery is running out , so I'll make this short
Find+awk oneliner
find . -type f -printf "%f\n" | awk -F "_"
'{ORIG=$0;gsub(/\_[[:digit:]].*\_time/,"_");gsub(/\.[[:digit:]].*\.jpeg/,".jpeg"); NEW=$0;cmd="mv "ORIG"
"NEW;system(cmd)}'
Demo
testdir2:$ ls
test_13442_time1446925878.1.jpeg test_27796_time1446925887.4.jpeg
test_25495_time1446925884.3.jpeg test_29681_time1446925881.2.jpeg
testdir2:find . -type f -printf "%f\n" | awk -F "_"
'{ORIG=$0;gsub(/\_[[:digit:]].*\_time/,"_");gsub(/\.[[:digit:]].*\.jpeg/,".jpeg"); NEW=$0;cmd="mv "ORIG"
"NEW;system(cmd)}'
testdir2:$ ls
test_1446925878.jpeg test_1446925881.jpeg test_1446925884.jpeg test_1446925887.jpeg
Sergiy Kolodyazhnyy
- 107,582