1

I had an issue with my Linux SAMBA server and it has corrupted a good few of my photos (several hundreds of files in tens of directories). I have a Mac with a time machine backup and it has a good number of the originals throughout.

With the SAMBA share mounted on my mac I can search for zero kb files

find /Volumes/Photos/ f -empty -not -path '*/\.*'

How can I expand this command to search my mounted time machine to see if any zero kb files have a non corrupt equivalent?

I'm thinking I need a bash script. Or maybe Python.

4
  • Is the non-corrupt equivalent file have the same name? Anyway, your find command is missing the -type before the single f Commented Jul 25, 2021 at 4:49
  • Yes, the same name is present Commented Jul 25, 2021 at 4:56
  • If the two sets of files are stored in identical hierarchies, you could just use rsync to copy the the good hierarchy over the bad one. Commented Jul 25, 2021 at 6:38
  • Unfortunately the good files are all over the place Commented Jul 25, 2021 at 6:59

1 Answer 1

0

I could only test the following on linux and not on mac, but I don't think it uses anything non-standard.

Won't work if filenames exists starting with dash - or if any filenames contain the newline character.

I started with a directory containing the following:

$ find -type f | xargs du -h
4,0K    ./find_empty_dupes.sh
4,0K    ./sub/sub2/corrupt.txt
0   ./sub/corrupt.txt
0   ./sub/empty.txt

And ran the following script:

#!/bin/bash

find . -type f -empty | while IFS= read -r file; do
    if find . -name "$(basename "$file")" -not -empty | grep -q '.'; then
        echo "$file"
    fi
done

This is the test run:

$ ./find_empty_dupes.sh 
./sub/corrupt.txt

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.