how to rename files recursively, only keeping last x digits plus extension
sorry if this has been answered (directly or indirectly) before, but I'm not really a programmer and after reading a lot of threads and man pages today with still no luck, I guess it's time to ask.
My problem is this:
I have a number of directories, all containing files of different name lenghts, including letters, numbers and possibly spaces. I want to recursively rename all of these files, so that only the _last_ 5 digits (not counting the extension) remain. In other words: I want to cut off all but the last 5 digits and not touch the extension.
I've tried to read up on tr, rename (perl version), sed, cut etc. and browsed through some threads here, but so far couldn't quite figure out how to do it.
If someone could point me to the right (standard) CLI tools and syntax, I'd heavily appreciate it! Thank you!
Not tested so only to illustrate the method
That is quite an impressive illustration, sir! It works like a charm! :)
Thanks a lot!
I'll have to do some reading before I fully understand your script. Seems it's mainly using pure bash functionality to 'parse' the filenames and put the desired parts back together. I don't think I would have found this solution by myself, so again, thanks for your help!
|All times are GMT -5. The time now is 12:16 PM.|