I have a directory (Directory A) with files.
Directories B and C contain files from directory A (no files in B are in C and vice versa).
How can I list files in Directory A that are not present in Directories B nor C?
I have a directory (Directory A) with files.
Directories B and C contain files from directory A (no files in B are in C and vice versa).
How can I list files in Directory A that are not present in Directories B nor C?
If you don't need to be fast in very-high-volume cases:
for f_path in a/*; do f=${f_path#a/}
[[ -e "b/$f" || -e "c/$f" ]] && continue
printf '%s\n' "$f"
done
If you do, and have GNU comm
, find
and sort
, see the following -- of course, replace the tr
at the end with code that actually reads a NUL-delimited list properly if you want to be able to safely handle all possible filenames:
comm -z23 <(find a -maxdepth 1 -printf '%P\0' | sort -z) \
<(find b c -maxdepth 1 -printf '%P\0' | sort -z) \
| tr '\0' '\n'
For more on this use of comm
, see BashFAQ #36.