0

I have a bunch of files names topic1.pdf, topic2.pdf, ... which I want to rename to newName1.pdf, ... is there any way this can be done 'neatly' as in something like $ mv topic*.pdf newName*.pdf?

1 Answers1

0

You can do it with a one-liner for loop (this assumes bash or similar)

for file in topic*.pdf; do mv "$file" "${file/topic/newName}"; done

If your shell can't do that substitution, you can use sed instead:

for file in topic*.pdf; do mv "$file" "$(printf "%s\n" "$file" | sed 's/topic/newname/')"; done
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
seumasmac
  • 2,015