I have a lookup file containing filenames. I also have a directory containing files, some of which have the names that correspond to some of the names in the directory.
How can I:
- Move exact matching files to a new directory or
- Remove non-matching files from the existing directory
Also, how can I do this recursively through a top-level directory and its subdirectories?
for x in $(cat list); do ls **/$x; done
), although you'd have to test each name in the expansion of **/$x to rule out directories, or give the names tofind
and have it move the matches withmv
, the problem is, if you have more than one match for the same name, how would you handle (1.)?