Compare folders and find missing files
Ken D'Ambrosio
ken at jots.org
Wed Mar 25 12:52:11 UTC 2020
On 2020-03-25 06:12, Peter Flynn wrote:
> On 25/03/2020 09:02, Chris Green wrote:
>> On Wed, Mar 25, 2020 at 12:40:09AM -0700, P. Echols wrote:
NB: the following might give false positives, as the unqualified
filename is being searched for, and, depending on your hierarchy, you
might have multiple directories with files with the same name.
> $ find /media/project/ -type f -exec basename {} \; | while read
> fname; do if [ `find ~/Documents/sub-tree -name "$fname" | wc -l` -eq
> 0 ]; then echo $fname not there; fi; done
My approach, while less elegant, is more explicit, and doesn't
repeatedly walk the compared tree:
cd /media/project && find . -type f | while read fname; ls
~Documents/sub-tree/$fname > /dev/null 2> /dev/null || echo "$fname not
there."
Note that there will be a superfluous -- but functionally noop -- "./"
in the path shown of any missing files.
None of which invalidates the point about diff possibly being the most
efficient method.
$.02,
-Ken
More information about the ubuntu-users
mailing list