Partial Multiple File Naming in Ubuntu
-
21-12-2019 - |
Question
I want to rename files from:
my.fi.name.123.txt, my.fi.name.124.txt, my.fi.name.125.txt etc2 into
new.file.link.123.txt, new.file.link.124.txt .. etc2.
What's the best command to do this in ubuntu 12.04?
Solution
You can do something like:
for file in my*; do mv ${file} "${file/my.fi.name/new.file.link}"; done
Test:
$ ls -l
total 0
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 my.fi.name.125.txt
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 my.fi.name.124.txt
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 my.fi.name.123.txt
$ for file in my*; do mv ${file} "${file/my.fi.name/new.file.link}"; done
$ ls -l
total 0
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 new.file.link.125.txt
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 new.file.link.124.txt
-rw-r--r-- 1 jaypalsingh staff 0 Feb 25 19:33 new.file.link.123.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow