Results 1 to 3 of 3

Thread: Bash script to remove iTunes duplicates

  1. #1
    Join Date
    Jul 2006
    Location
    Brittany, France
    Beans
    197
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Bash script to remove iTunes duplicates

    Hi,

    I'm trying to remove duplicate MP3 files from a iTunes library of around 15,000 tracks with about 10,000 duplicates.

    The duplicates all have the suffix ' 1.mp3', e.g.

    Music/artist/album/tracka.mp3

    but there also exists

    Music/artist/album/tracka 1.mp3

    I'd like to remove all the files with the suffix ' 1.mp3' iff the file without the ' 1' suffix exists in the same directory.

    I've tried various combinations of find, sed, xargs etc. but my bash knowledge/syntax is limited.

    E.g.

    Code:
    $ find Music -type f -name '* 1.mp3' | xargs -0 sed 's: 1.mp3:.mp3:' -exec [ -f ?? ] echo rm ?
    I know the above find command is nonsense, but maybe it shows what I'm trying to do.

    Any help really appreciated.
    Ian

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Bash script to remove iTunes duplicates

    try this
    Code:
    while IFS= read -rd $'\0' f
    do
      [ -f "${f% 1.mp3}.mp3" ] && echo rm "$f"
    done < <( find Music -iname '* 1.mp3' -type f -print0 )
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Jul 2006
    Location
    Brittany, France
    Beans
    197
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Bash script to remove iTunes duplicates

    Thank you. Works perfectly.

    I never knew about f%
    Ian

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •