I have 4 files to rename:
./01:
I0010001 I0020001
./02:
I0010001 I0020001
I want to add auxiliary filename .dcm
to each file, so I have tried:
$ mv \(*/*\) \1.dcm
mv: cannot stat '(*/*)': No such file or directory
$ mv \(./*/*\) \1.dcm
mv: cannot stat '(./*/*)': No such file or directory
$ mv \(./\*/\*\) \1.dcm
mv: cannot stat '(./*/*)': No such file or directory
$ mv "\(./*/*\)" "\1.dcm"
mv: cannot stat '\(./*/*\)': No such file or directory
$ mv 0\([1-2]\)/I00\([1-2\)]0001 0\1/I00\20001.dcm
mv: cannot stat '0([1-2])/I00([1-2)]0001': No such file or directory
$ mv "0\([1-2]\)/I00\([1-2\)]0001" "0\1/I00\20001.dcm"
mv: cannot stat '0\([1-2]\)/I00\([1-2\)]0001': No such file or directory
$ mv "0\([1-2]\)/I00\([1-2]\)0001" "0\1/I00\20001.dcm"
mv: cannot stat '0\([1-2]\)/I00\([1-2]\)0001': No such file or directory
$ mv "0\([[:digit:]]\)/I00\([[:digit:]]\)0001" "0\1/I00\20001.dcm"
mv: cannot stat '0\([[:digit:]]\)/I00\([[:digit:]]\)0001': No such file or directory
$ mv "0\([1-2]\)\/I00\([1-2]\)0001" "0\1/I00\20001.dcm"
mv: cannot stat '0\([1-2]\)\/I00\([1-2]\)0001': No such file or directory
$ mv \(*\) \1.dcm
mv: cannot stat '(*)': No such file or directory
None of them yield the result I want.
You don't really need regular expressions here, this is very simple with a
for
loop:For more complex situations, you should be looking into the
rename
program (prename
on some systems), which uses powerful Perl regular expressions to handle the renaming. Though unnecessary here, this simple case would use:That
-n
is debug mode (print what would happen but don't actually rename). Remove it once you're happy it will do what you want.