Rename list of files from command promp!!!
Suppose I have the following files:
1132_1_fr.mp3 1132_2_fr.mp3 1132_3_fr.mp3 . . . 1132_3_fr.mp3 PD_1132_65_fr.mp3 PD_1132_7_fr.mp3 . . . I want to rename them so everyone look like: PD_1132_1.mp3 PD_1132_2.mp3 PD_1132_3.mp3 . . . PD_1132_65.mp3 So I want to add PD_ to those who dont have this preindex and get rid of _fr. Please help....basically rename files in a same directory!! |
Code:
for i in *fr.mp3; do echo mv $i $( echo "PD_"$(echo $i|egrep -o '[0-9]{4}_[0-9]+')".mp3" ); done When you're sure it works, remove the bold echo. |
man bash, man sed, man any_decent_editor
There are like a thousand of ways to do this, you should try google too.
The shortest way (to explain) is using bash like this: Code:
for FILE in $(ls PD_*fr*mp3); do mv $FILE "${FILE//_fr}" ; done Code:
for FILE in $(ls [0-9]*mp3); do mv $FILE PD_"${FILE//_fr}" ; done The second one moves any file starting with a number and ending mp3, to PD_"+its name". So no files starting with PD_ will be changed. But any already existing files would be overwritten. Might want to try "mv -i" just in case. |
Thanks...now how do I create bash? (Sorry Im pretty new at linux...I know what it is but I dont know how to create it.)
|
Bash is the default shell in most distributions. Any time you open a terminal, you are using bash.
In brief you can either enter those commands into the terminal to run it, or create a script. A script is just a text file with the commands, basically. So it might look like Code:
#!/bin/sh http://en.wikipedia.org/wiki/Bash http://tldp.org/LDP/abs/html/ |
Thank you.. I got it working but I tried it again and....
~\EXAMPLE> ./exe | sh mv: cannot stat `*fr.mp3': No such file or directory My file editor: #!/bin/sh for i in *fr.mp3; do echo mv $i $( echo "PD_"$(echo $i|egrep -o '[0-9]{4}_[0-9]+')".mp3" ); done |
And?
Are those files in the EXAMPLE directory? Btw, if you get rid of the first echo as I suggested in my first post you save yourself the "| sh" Cheers, Tink |
All times are GMT -5. The time now is 02:51 PM. |