I have number of files in a directory and a list of expected files in it.For example:files I have are:file1file2file3expected files are file1file2file4I'd like to test the dir and find that file4 is NOT in it.
Bash - How to find all files NOT in array
bash;shell script
Assuming you have an array with the filenames and want to find out which ones are not present in the directory, just loop through the array, and check if the files exist. (-f tests for regular files, -e for any type)files=(file1 file2 file4)for f in ${files[@]} ; do     [ -f $f ] || echo $f: not founddone The opposite is similar, but requires a double-loop or turning the array into an associative array. With the double-loop:files=(file1 file2 file4)for f in * ; do        found=0        for g in ${files[@]} ; do                [ $f = $g ] && found=1        done        [ $found = 0 ] && echo $f: in directory but not listeddone 