Portal Home > Knowledgebase > Articles Database > Copy or Rename files *.JPG as *.jpg


Copy or Rename files *.JPG as *.jpg




Posted by hbhb, 09-12-2010, 12:14 PM
I have hundreds of files with a .JPG extension on a directory. I wanted to mass-copy or rename it as .jpg (small case), without overwriting existing file (if file exist) For example: abc.JPG -> abc.jpg (Fail: file exist) abc.jpg xyz.JPG -> xyz.jpg (Success) Anyone can help? I try to search for the right command or script to do that but to no avail..

Posted by helpyoulinux, 09-12-2010, 12:53 PM
I hope you are using a *NIX based machine. Here you go. for i in $(ls -1 *.JPG) do pre=$(echo $i | cut -d "." -f1) cp -v $i ${pre}.jpg done Please run it on bash.

Posted by helpyoulinux, 09-12-2010, 01:02 PM
This is for copying , if you want to rename use mv instead of cp

Posted by hbhb, 09-12-2010, 02:08 PM
will it prompt question to overwrite file (y/n?) because i have over 500 files

Posted by helpyoulinux, 09-12-2010, 02:53 PM
In that case, you have to use cp -f it will do the trick.

Posted by hbhb, 09-12-2010, 11:30 PM
Supposely I do not want it to overwrite file. Default answer should be a 'NO' -f sounds like 'force' to 'YES' ?

Posted by LnxtecH, 09-13-2010, 08:02 PM
If you do not want to overwrite then use the command



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
burst.net anyone? (Views: 616)

Language: