I have multiple files in a directory:
$ ls -1
04PD.001
04PD.002
04PD.003
04PD.004
04PD.005
Now I'd like to change the name of each file to something like 04PD.7z.0*
Can someone tell me what's wrong with that command:
$ find 04PD* -type f -print -exec mv \{\} `echo \{\} | sed "s/04PD\.0/04PD\.7z\.0/"` \;
The result is utmost strange:
$ find 04PD* -type f -print -exec mv \{\} `echo \{\} | sed "s/04PD\.0/04PD\.7z\.0/"` \;
04PD.001
mv: '04PD.001' and '04PD.001' are the same file
04PD.002
mv: '04PD.002' and '04PD.002' are the same file
04PD.003
mv: '04PD.003' and '04PD.003' are the same file
04PD.004
mv: '04PD.004' and '04PD.004' are the same file
04PD.005
mv: '04PD.005' and '04PD.005' are the same file
To test the command I changed the command to simple echo:
$ find Pop*04PD* -type f -print -exec echo mv \{\} `echo \{\} | sed "s/04PD\.0/04PD\.7z\.0/"` \;
04PD.001
mv 04PD.001 04PD.001
04PD.002
mv 04PD.002 04PD.002
04PD.003
mv 04PD.003 04PD.003
04PD.004
mv 04PD.004 04PD.004
04PD.005
mv 04PD.005 04PD.005
Note: I've already found a very nice & simple solution with a loop, so please focus on what's wrong with this command, rather that proposing another solution.
I am pretty curious where the error is.
mv
command toecho mv
and see what you get – Chris Davies Jun 04 '20 at 17:00