0

I have a lot of files i've copied over from my iphone file system, to start with they were mp3 files, but app on iphone changed their names to some random staff which looks like:

1c03e04cc1bbfcb0c1237f57f1d0ae2e.mp3?extra=f7NhT68pNkmEbGA_I1WbVShXQ2E2gJAGBKSEyh3hf0hsbLB1cqnXDuepYA5ubcFm_B3KSsrXDuKVtWVAUh_MAPeFiEHXVdg

I only need to remove part of file name after mp3. Please give me a script - there are more than 600 files, and manually it is impossible.

4
  • Try mmv Commented Jul 27, 2014 at 8:20
  • @Jens i am very bad with terminal and don't think mmv would help. All it really needs is some kind of instr function. Like regexp_instr in oracle to get position where that question mark starts, and then get substring and rename. Commented Jul 27, 2014 at 8:23
  • possible duplicate of Rename multiple files in Unix Commented Jul 27, 2014 at 8:36
  • @buff i were looking for rename script using regex, but simple rename command solved it in no time Commented Jul 27, 2014 at 8:39

2 Answers 2

2

you can use rename command:

rename "s/mp3\?.*/mp3/" *.mp3*
Sign up to request clarification or add additional context in comments.

Comments

1
#!/bin/bash
shopt -s nullglob
for F in *.mp3\?*; do
    echo mv -v -- "$F" "${F%%.mp3\?*}.mp3"
done

Save it to a script like script.sh then run as bash /path/to/script.sh in the directory where the files exist.

Remove echo when you find it correct already.

3 Comments

Since the OP has over 600 files, he probably should pipe his output to "less" so that he can quicker and easier see what is happening (without waiting for all the lines to scroll by). Example ./script.sh | less when running is test with the echo.
@L.D.James Yes that can be an option. And better have less -S.
@konsolebox this script is nice and answer is well thought, preventing any damage to file names, thanks but i saw the other answer first and it worked with about 10 files which couldnot be renamed dew to same name error - dublicates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.