Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

unRAIDFindDuplicates.sh

Featured Replies

I'm trying to find duplicate files between my cache and array (basically where mover wrote the file to the array but didn't successfully remove it from the cache so now its on both cache and array), by default it doesn't seem to do this.

it looks like -D should do what I want, but it seems to be broken

root@UnraidHost:/mnt/user/Media# ./unRAIDFindDuplicates.sh -v -D /mnt/cache_unprotected

============= STARTING unRAIDFIndDuplicates.sh ===================

Included disks:
   /mnt/disk/mnt/cache_unprotected
   /mnt/disk1
   /mnt/disk2
   /mnt/disk3
   /mnt/disk4
   /mnt/disk5
   /mnt/disk6
   /mnt/disk7
   /mnt/disk8
   /mnt/disk9
   /mnt/disk10
   /mnt/disk11
   /mnt/disk12
   /mnt/disk13
   /mnt/disks

Included shares:
   Backup
   CommunityApplicationsAppdataBackup
   LibVirtBackup
   Media
   ...

List duplicate files
./unRAIDFindDuplicates.sh: line 373: verbose_to_bpth: command not found
./unRAIDFindDuplicates.sh: line 404: cd: /mnt/disk/mnt/cache_unprotected: No such file or directory
checking /mnt/disk/mnt/cache_unprotected
    Backup
^C
root@UnraidHost:/mnt/user/Media# 

it seems to concat /mnt/disk onto the path specified by -D which seems incorrect?

 

if I let it run it seems to list every file in the array as duplicate after it gives an error on line 404.

  • Replies 112
  • Views 52.5k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • Would it be possible to only list the duplicate entry instead of both ? With that it would be extremely easy to an editor to add "RM" in front of that and simply delete the duplicate entries..

  • A script I wrote a while back to find duplicate files is described in and attached to this post: http://lime-technology.com/forum/index.php?topic=7018.msg68073;topicseen#msg68073 It is a series of

  • Joe:  I have added a link to the post describing your utility to my opening post in this thread.    I think your utility satisfies a slightly different need as it may be perfectly legitimate to h

Posted Images

  • Author

It might do what you want if you change line 215 that reads:

    D ) include_disks[$include_disks_count]="/mnt/disk${OPTARG}"

to be:

    D ) include_disks[$include_disks_count]="${OPTARG}"

 

In addition line 373 should be

  verbose_to_both ""

although that is just a cosmetic change

 

Could you let know if that does the job as if it does I can change the linked script to include these changes.  Unfortunately not in a good position to check the changes myself at the moment.

 

EDIT:  Updated the script attached to the first post to include the above changes.

 

On 6/3/2024 at 2:38 PM, itimpi said:

 

EDIT:  Updated the script attached to the first post to include the above changes.

 

The 1.6 version has a couple of issues. Missing closing quotation marks on lines 95 an 101 prevent it from running, and "preogram_dir" is misspelled on line 49 which makes that check fail silently. The version number returned from -V was incorrect, also. 

 

Here's an updated file with those issues fixed.

 

unRAIDFindDuplicates v1.7.zip

Edited by WalkerJ

  • Author

Thanks for the fixed version - I will update the first post in the thread with this version.    I hope with those fixes you got useful results?   

 

It is nearly 10 years since I originally developed this script early in my Unraid days (using an early v5 beta release) when I had unreliable disks and ended up with lots of duplicate files while sorting this out.  Despite all the changes that have happened in this time at the Unraid level it is interesting to see that the basic concepts have remained constant so that this script still works.

 

BTW:  Another interesting fact - assuming you username is based on your surname then we have the same surname 🙂

  • 4 months later...

Nice script. You save my day :D. It would be even better if this script can group all files to the corresponding folders because my files was all over disks and It look so messy.

Edited by Taipt5

  • 3 weeks later...

Hello @itimpi,
can you reupload your script? 

When i hit the download button it gives me an error.
And yes i'm logged in.

 

thanks

  • 1 month later...

The script is able to tell me the duplicate files at the share level, but can the script tell me which drives?

I need to know the drives I can delete the duplicated files from.

 

Thanks.

  • 3 months later...

@itimpi

The script in Unraid 7 seems to completely fail to work. First, it skips ZFS arrays, so you have to add them via the -D parameter.

 

obraz.thumb.png.5cd0e824589c04ad1a2b3e5ec6dacbc6.png

 

obraz.thumb.png.7793d8f8020adc4a58b20213096c2c45.png

 

But still, it doesn't find duplicates at all, even when I deliberately created them:

 

 

obraz.thumb.png.bb02ce0a18df8e1c492d1e305dbc6581.png

 

 

Edited by jaclas

  • Author

The script ignores pools - it predates pools being generally used for anything other than caching so only checks the main Unraid array.

 

I guess at some time it might be worth considering updating it to handle pools, and also make it a plugin and provide some sort of GUI front end.   I will put it on my 'to do' list, but no promises.

@itimpi I'll just add some more questions just to be sure.

So even though the pool is explicitly pointed out it is ignored? And even though there is information in the log about checking this pool it is really bypassed?

  • Author
1 hour ago, jaclas said:

@itimpi I'll just add some more questions just to be sure.

So even though the pool is explicitly pointed out it is ignored? And even though there is information in the log about checking this pool it is really bypassed?

Your question made me look at the code - you are right there is some explicit code at around lines 311-312 which looks for /mnt/cache and if present adds that to the list of disks (as at the time the script was developed that was the only pool available and its name was fixed).

 

That looks like it is the area at which one could add any additional pools if present to get them included in the check to make the script able to handle other pool names.

Your script was super helpful for me.

 

I ended up writing a script to follow up and act on (delete) duplicates.

#!/bin/bash

dupeList=(
)

remove_dupes() {
  dupe="$1"

  dupePaths=$(find /mnt/disk*/"${dupe}")
  dupeCount=$(echo "${dupePaths}" | wc -l)

  if [[ "${dupeCount}" -gt 1 ]]; then
    removeFiles=$(echo "${dupePaths}" | sort -R | tail -n +2)
    keepFile=$(grep -v -F -x -f <(echo "${removeFiles}") <(echo "${dupePaths}"))
    echo "------------------------------------"
    echo "Found ${dupeCount} duplicates for:"
    echo "${dupe}"
    echo ""
    echo "Keeping one file:"
    echo "${keepFile}"
    echo ""
    echo "Removing duplicate file(s):"
    echo "${removeFiles}"
    # rm "${removeFiles}"
    echo ""
    echo "Remaining files (confirmation):"
    find /mnt/disk*/"${dupe}"
    echo "------------------------------------"
  fi
}

for dupe in "${dupeList[@]}"; do
  remove_dupes "${dupe}"
done

The rm line in the above is commented out. If anyone decides to use this script, be sure you know what you're doing (or run it first with the rm commented).

Also the dupeList variable is empty. It doesn't detect the /boot/duplicates.txt, I am just taking the output from there and copying it into the script (with quotes) so it looks like this:

dupeList=(
  "file1.txt"
  "file2.txt"
  "file3.txt"
  "file4.txt"
  "file5.txt"
  "file6.txt"
  "file7.txt"
  "file8.txt"
  "file9.txt"
  "file10.txt"
  # Add more files as needed
)

It could probably be easily modified to actually read from /boot/duplicates.txt but having to manually copy keeps the use of this script very intentional.

 

One last note, it decides which file to keep randomly and deletes the rest. The point isn't to gather/scatter line unbalanced, or keep files together on specific disks, just to get rid of duplicates to recover space.

  • 4 weeks later...

@iXNyNe

Great script, I just added this just before the RM statement:

echo "Deleting now, you have 2 seconds to break here to stop. Use Ctrl-C to break"

sleep 2

Slows this down, but it at least gives you time to kill it before it deletes in case you see something you don't like.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.