Say I want to copy the contents of a directory excluding files and folders whose names contain the word \'Music\'.
cp [exclude-matches] *Music* /target_direc
A trick I haven't seen on here yet that doesn't use extglob
, find
, or grep
is to treat two file lists as sets and "diff" them using comm
:
comm -23 <(ls) <(ls *Music*)
comm
is preferable over diff
because it doesn't have extra cruft.
This returns all elements of set 1, ls
, that are not also in set 2, ls *Music*
. This requires both sets to be in sorted order to work properly. No problem for ls
and glob expansion, but if you're using something like find
, be sure to invoke sort
.
comm -23 <(find . | sort) <(find . | grep -i '.jpg' | sort)
Potentially useful.