LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to modify the names of files and replace characters with other characters or symb (https://www.linuxquestions.org/questions/linux-general-1/how-to-modify-the-names-of-files-and-replace-characters-with-other-characters-or-symb-507837/)

peter88 12-06-2006 01:57 AM

How to modify the names of files and replace characters with other characters or symb
 
Hi, Does anyone have a script which does the following please:

Say you have a directory with files some of which you wish to change their name because perhaps they contain unwanted symbols like ~ , e.g. ~200005_tom_Berry_8.jpg . Lets say I want to replace the ~ with x and _ with - --> x200005-tom-Berry-8.jpg .

Ideally I would like to run the script from CWD and apply it to all the sub-directories (or use the find..-exec )in that filesystem, and not only be able to change the names of files but any directory names which match the criteria, however so long as I can do it an individual dir that will be fine for now.

Any ideas welcome. TIA.

acid_kewpie 12-06-2006 02:30 AM

for i in *.jpg
do
mv $i $(echo $i | tr '~' 'x' | tr '_' '-')
done

peter88 12-10-2006 03:05 AM

Thanks a lot for your suggestion, I will try it :)


All times are GMT -5. The time now is 12:59 PM.