Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'One-line batch file renamer' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
One-line batch file renamer
Authored by: blueshifter on Feb 26, '10 04:43:02AM
here's my version, the OP didn't allow me to append a file type to the original file, which were of form "foonnn", where nnn represent the numbers 1 through 500.

test version:
ls | egrep "foo[0-9]*" | while read filename; do echo "mv $filename $filename.jpg" ; done

doit version:
ls | egrep "foo[0-9]*" | while read filename; do mv $filename $filename.jpg ; done

[ Reply to This | # ]

One-line batch file renamer
Authored by: carmatana on Jan 05, '11 05:22:39AM

Hi loubregand,

Your lines have been the more helpful of all that I tried. I have one question: What if I want to make the rename (sed) just on files, excluding folders or directories at all. I have tried:

find . -type f -iname "*pattern1*" -exec echo "mv '{}' '{}'" \; | sed 's/pattern2/pattern3/2' | /bin/sh

and several more permutations but with no success

something that works is to use for pattern1 somethin like "*pattern1*.*"
and this works as long as the file has an extension (and if directories do not have dots in their names), if it does not have one it is not processed

Could you or someone else can help me?



[ Reply to This | # ]
One-line batch file renamer
Authored by: Neville Hillyer on May 11, '11 12:32:44PM

I have very limited experience in this area but was surprised by carmatana's remark so I did a few tests.

My tests indicate that '-type f' restricts 'find' to files (ie not directories) as the manual says.

Edited on May 11, '11 12:40:37PM by Neville Hillyer



[ Reply to This | # ]