View Single Post
Posts: 303 | Thanked: 175 times | Joined on Oct 2009 @ London UK
#3
Ouch.. calling sed for each file, and not space filename safe

try this.. to rename all files in the current directory and below (including sub-directories).

find . -type f -name "*.jpg" | while IFS="" read file ; do mv "$file" "${file%.jpg}.jp1" ; done


If you want to rename only the files in the current directory, and not any files in sub-directories below:

for file in *.jpg ; do mv "$file" "${file%.jpg}.jp1" ; done


${file%.jpg} => strip ".jpg" from the end of $file
${file%.jpg}.jp1 => Strip .jpg1 from end of $file, then append .jp1

file=fish.jpg
fish.jpg => fish.jp1

neat
 

The Following User Says Thank You to cpitchford For This Useful Post: