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
?
Asked
Active
Viewed 25 times
0
-
@Panki That did the trick. this answer, specifically. – dolefeast Dec 09 '22 at 12:46
1 Answers
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