Search code examples
macosshellscriptingmove

Move Latest version -only- of iOS Apps files from "Mobile Applications" folder to a new folder


As you may know, iTunes do not delete old versions of iOS Apps when download a newer version of them
This ends of huge size of "Mobile Applications" folder (more than 5GB)

What I want to do is moving all latest version -only- of iOS apps files from "Mobile Applications" folder to a new folder "Lastest iOS App"

Note that, iOS Apps files name have the version number

Example

Before : "Mobile Applications" Folder:
CutTheRope 1.2.ipa
CutTheRope 1.4.ipa
CutTheRope 2.0.ipa
AngryBirds 1.1.ipa

After "Mobile Applications" Folder :
CutTheRope 1.2.ipa
CutTheRope 1.4.ipa

"Lastest iOS App" Folder:
CutTheRope 2.0.ipa
AngryBirds 1.1.ipa

P.S
I am using Macbook and I do not have experience with Shell commands (Mac & Linux) or programming on it (I have Java/C++ programming experience)


Solution

  • You might use a command like this:

    ls|gsort -rV|sort -uk1,1|while read f;do mv "$f" ~/Desktop/Latest;done
    

    -V sorts version numbers in GNU sort. You can install GNU sort with brew install coreutils.

    sort -uk1,1 prints the first line from each run of lines where the first column (-k1,1) is the same.