Is there a way to show "File not found" or a message alike when using the `find` command?

jimm-cl

I'm trying to check the existence of several files, without knowing in advance where the files are located. So, I thought of find as the de facto utility to do this... It works as expected, but the problem is that it does not acknowledge the non-existence of files, that is, if a file does not exists under the searched directory then, as you will expect, it's not showed in the results.

I guess this is fine, as the find command is meant to find files, which actually exists in the first place (d'oh). But I wonder if there's a way for the find command to return a message like "File not found" or alike, to inform that the file is not there, instead of failing (or succeeding) silently.

I thought that maybe I could workaround the problem by using find's return code by querying $?, but even when the file is not found the return code is 0.

Just an example of what I have...

find . -name foo.sh 
find . -name bar.sh 

and what it returns in case the only file in there is foo.sh:

./directory/foo.sh

What I would like to receive is:

./directory/foo.sh
bar.sh not found

Does anyone knows of a find flag or any other workaround I can use?
Thanks!

user322483

you could try find . -name foo | grep \/ to set the exit code.

grep looks for any / in the output and returns exit code 1 if none is found

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Open file found with 'find' command

From Dev

Open file found with 'find' command

From Dev

PHP file not found when using GET

From Dev

When using os.startfile file is not found

From Dev

Running a Bash function for each file found with the find command

From Dev

error when executing find command using variable

From Dev

Git Command to find all files using commit message

From Dev

File not found error when running an exe using Shell function

From Dev

restkit.h file not found when archiving using xcode 6

From Dev

restkit.h file not found when archiving using xcode 6

From Dev

File not found when using file after selecting it Android

From Dev

File not found when using FacebookSDK with React Native < 0.40.0

From Dev

Message box show output of command

From Dev

Enable button when passwords are alike

From Dev

how to show a message using jquery in html when radio button is enabled

From Dev

Is there a way to tell my makefile to output a custom error message if a certain an include file is not found?

From Dev

gnu make message file not found

From Dev

Removing the warning message that pops up when using an at command

From Dev

Mac OS X: Is there a way to jump to a folder containing a file found in command-space

From Dev

File not found using fread

From Dev

Command for reloading file from disk to show changes when using “less?”

From Dev

Don't show hidden applications when using Command-Tab

From Dev

The command "find" output an error message

From Dev

Command Prompt: java file not found

From Dev

Execute a command where a file is found

From Dev

Where is the echo command file found

From Dev

I find this error message when I'm using xml in r

From Java

when using SoapUI, is there a way to show multiple Requests on the same page?

From Dev

Why am I getting "File Not Found" when typing "dir" in the command prompt?

Related Related

  1. 1

    Open file found with 'find' command

  2. 2

    Open file found with 'find' command

  3. 3

    PHP file not found when using GET

  4. 4

    When using os.startfile file is not found

  5. 5

    Running a Bash function for each file found with the find command

  6. 6

    error when executing find command using variable

  7. 7

    Git Command to find all files using commit message

  8. 8

    File not found error when running an exe using Shell function

  9. 9

    restkit.h file not found when archiving using xcode 6

  10. 10

    restkit.h file not found when archiving using xcode 6

  11. 11

    File not found when using file after selecting it Android

  12. 12

    File not found when using FacebookSDK with React Native < 0.40.0

  13. 13

    Message box show output of command

  14. 14

    Enable button when passwords are alike

  15. 15

    how to show a message using jquery in html when radio button is enabled

  16. 16

    Is there a way to tell my makefile to output a custom error message if a certain an include file is not found?

  17. 17

    gnu make message file not found

  18. 18

    Removing the warning message that pops up when using an at command

  19. 19

    Mac OS X: Is there a way to jump to a folder containing a file found in command-space

  20. 20

    File not found using fread

  21. 21

    Command for reloading file from disk to show changes when using “less?”

  22. 22

    Don't show hidden applications when using Command-Tab

  23. 23

    The command "find" output an error message

  24. 24

    Command Prompt: java file not found

  25. 25

    Execute a command where a file is found

  26. 26

    Where is the echo command file found

  27. 27

    I find this error message when I'm using xml in r

  28. 28

    when using SoapUI, is there a way to show multiple Requests on the same page?

  29. 29

    Why am I getting "File Not Found" when typing "dir" in the command prompt?

HotTag

Archive