Thursday, 1 May 2014

Howto verify all files of first directory hierarchy reside somewhere in second hierarchy.

Imagine, you took a huge bunch of files residing in one directory subtree and you re-arranged them in a new directory hierarchy and now you want to prevent loss of any file.

The following command will read all filenames from ORIGINDIR directory and search for the filename in destination directory DESTDIR subtree. If the filename is not found, print it to console:
 
find ORIGINDIR -type f  | while read ENTRY ; do case `find DESTDIR  -name  $(basename $ENTRY) -print -quit` in '') echo "? $ENTRY" ;; *) echo -n "" ;; esac ; done