Find the answer to your Linux question:
Results 1 to 2 of 2
Hello there, Anyone knows how to manage the find command to return true or false if a file was found/or not? I tried to man find but didn't found anything. ...
  1. #1
    Just Joined!
    Join Date
    May 2011
    Posts
    5

    find command return true if a file was found

    Hello there,

    Anyone knows how to manage the find command to return true or false if a file was found/or not? I tried to man find but didn't found anything.

    Regards,

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    The exit status of a program is written into it and can't be changed by a user. The behaviour of find in this respect is described in the man page:
    "find exits with status 0 if all files are processed successfully, greater than 0 if errors occur. "

    If you want a command that returns 1 when a file is not found, try piping a listing of the directory into grep. For a directory tree, use find -name "*" to list all subdirectories and their contents and pipe the result into grep.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...