0
$ find ./ -name "AABE*"  ## this returns nothing 
$ echo $? 
0

$ find ./ -name "AWGT*"  ## this returns locations of were files matching the criteria
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
$ echo $?
0
    
$ find ./ -type f -name "AWGT*" -o -name "SLIN*" -o -name "AABE*" -o -name "AMDM*" -o -name "ARDE*" -o -name "WTHC*" ## this returns locations of were multiple files matching the criteria
./Atempt3A/AMDM-modified.txt
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Atempt3A/WTHC-modified.txt
./Attempt2/164_sites/env_scripts/AMDM-modified.txt
./Attempt2/164_sites/env_scripts/WTHC-modified.txt
./Attempt2/179ish_sites_20220914/AMDM-modified.txt
./Attempt2/179ish_sites_20220914/WTHC-modified.txt
./Attempt5_Dec_2022/again/ARDE-modified.txt
./Attempt5_Dec_2022/again/SLIN-modified.txt
./Attempt5_Dec_2022/scripts/AMDM-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts/WTHC-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AMDM-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/ARDE-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/SLIN-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/WTHC-modified.txt
$ echo $?
0

What I want is the output to show something like: cannot find "AABE*" , or something to this affect can this be done?

related to this question but mine is slighly different Can I make `find` return non-0 when no matching files are found?

EDIT1-Answer

$ find ./ -type f -name "AWGT*" -o -name "SLIN*"     -o -name "AZZZ*" -o -name "AMDM*" -o -name "ARDE*" -o -name "AQQQ*" |     perl -pe '
        BEGIN{ our %h; our $error = 0; }
        $h{$1}++ if m/(AWGT|SLIN|AZZZ|AMDM|AQQQ)/;
        END{
            for ("AWGT", "SLIN", "AZZZ", "AMDM", "AQQQ") {
                if ($h{$_} == 0) {
                    $error = 1;
                    warn "cannot find $_\n"
                }

            }
            exit($error)
         }
    '
./Atempt3A/AMDM-modified.txt
./Atempt3A/AWGT-modified.txt
./Atempt3A/test_will_nov2022/AWGT-modified.txt
./Attempt2/164_sites/env_scripts/AMDM-modified.txt
./Attempt2/179ish_sites_20220914/AMDM-modified.txt
./Attempt5_Dec_2022/again/ARDE-modified.txt
./Attempt5_Dec_2022/again/SLIN-modified.txt
./Attempt5_Dec_2022/scripts/AMDM-modified.txt
./Attempt5_Dec_2022/scripts/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AMDM-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/ARDE-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/AWGT-modified.txt
./Attempt5_Dec_2022/scripts - added_morefrom_again_folder/SLIN-modified.txt
cannot find AZZZ
cannot find AQQQ
1
  • If an answer solves your problem, please accept it by clicking the large check mark (✓) next to it and optionally also up-vote it (up-voting requires at least 15 reputation points). If you found other answers helpful, please up-vote them. Accepting and up-voting helps future readers. Please see the relevant help-center article Mar 7, 2023 at 12:15

1 Answer 1

1

What I would do:

find ./ -type f -name "AWGT*" -o -name "SLIN*" \
    -o -name "AABE*" -o -name "AMDM*" -o -name "ARDE*" -o -name "WTHC*" |
    perl -pe '
        BEGIN{ our %h; our $error = 0; }
        $h{$1}++ if m/(AWGT|SLIN|AABE|AMDM|WTHC)/;
        END{
            for ("AWGT", "SLIN", "AABE", "AMDM", "WTHC") {
                if ($h{$_} == 0) {
                    $error = 1;
                    warn "cannot find $_\n"
                }
                
            }
            exit($error)
         }
    '

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .