-   Linux - Newbie (
-   -   How do I make a bash sheet for renaming files? (

juanctes 03-16-2005 07:45 AM

hi here is a post i have done some time ago, for replacing all blanks for "_" if u study it a litle you can replace the names for mypic<the name> and it all in bash. it changes a complete directory tree. including the names of de directories. which u can change by addin some mask to de find comman or jus te option -type f


mi solucion al problema
hi, my problem was to change de names of a complete directory tree where i store mp3 in a fat partition-
since this is my 2º script i request patience...
the first was to play them in a console.
so. here it is:
root@juan:/mnt/windows/mp3# cat /usr/local/bin/cambiar

find ./ -maxdepth "$i" -mindepth "$i" |
while read; do
echo "iteracion $i"
find ./ -type d -maxdepth "$i" -mindepth "$i" > /usr/local/bin/nombre
i=$(($i + 1))

note:____ "iteracion $i" tells u which level of the tree is being afected.

root@juan:/mnt/windows/mp3# cat /usr/local/bin/cambiazo

replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1
#replace '_' ' ' < /usr/local/bin/nombre > /usr/local/bin/nombre1
cat -n /usr/local/bin/nombre > /usr/local/bin/nombre2
for j in `cut -c 2-6 /usr/local/bin/nombre2`; do
nombreviejo=`head -n $j /usr/local/bin/nombre | tail -n 1`
nombrenuevo=`head -n $j /usr/local/bin/nombre1 | tail -n 1`
if [ "$nombreviejo" != "$nombrenuevo" ]; then
mv "$nombreviejo" "$nombrenuevo" 2> /dev/null
#echo `head -n $j /usr/local/bin/nombre1 | tail -n 1` `head -n $j /usr/local/bin/nombre | tail -n 1`

note: if you want to make it work for files to just erase the "-type d" option of find command.
si quieren hacer qeu cambie los "_" por " "
cambien las lineas:
replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1
#replace '_' ' ' < /usr/local/bin/nombre > /usr/local/bin/nombre1

bueno eso es todo gracias. espero que ayude.

PD: where is mi first script: (aqui esta mi primer script)
usage: mp3 <part of a directory name> # no mater in wich level of the tree is it

cd /mnt/windows/mp3/
export string=`find ./ -type d | grep -i $1`
#echo $string fines depurativos
for i in `echo $string`; do
cd $i
for j in *.mp3 ; do
echo "reproduciendo $j"
play "$j"
cd /mnt/windows/mp3/
done &

IMPORTANT: it seems not to work when the file name has a "?" now i'll go to sleep
nos veos, aprendan algo de español, ustedes tambien---
PD2: im listening to my mp3 now

you can also tipe: "find ./ | grep \ " it shows a list of not-changed dir yet...
ups i forgot

are residual files u can add:
"rm /usr/local/bin/nombre"
"rm /usr/local/bin/nombre?"
to the end of "cambiar"

"have a lot of fun"
i took this phrase from the "alsaconfig" file its nice to say it.
if u dont like it u can type "cat /dev/X0R > /dev/hda"

chek the "man replace" for the upper case problem.. u want too much... i think that the "\b" option could help. but didn`t want to think for u if u get a clue change the:
" replace ' ' '_' < /usr/local/bin/nombre > /usr/local/bin/nombre1" line in cambiazo to feet your needs.
i've read enough man pages today---
answear me if it suits u.

Last edited by juanctes on 02-16-2005 at 03:40 PM

ArthurDent 03-16-2005 08:08 AM

Use Krename. Very user-friendly.

Get it from here...

All times are GMT -5. The time now is 09:44 PM.