Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-08-2009, 04:09 PM   #1
LQ Newbie
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
Arrow exit status of command "find"

Hi all,
I am beginner in Linux.I want to do the following (bash shell):

if "find" command finds 'thereis' file in the current directory then "echo" Yes otherwise No.

Any ideas?

I tried to use exit status of "find" but it gives the same result in both cases.
Old 11-08-2009, 04:27 PM   #2
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,194

Rep: Reputation: 105Reputation: 105
Check the man page for find. The definition of the return status is rather broad, but it basically refers to all files having been processed successfully, not whether it found what you were looking for. There are other ways in the shell of asking whether a file exists or not.
Old 11-08-2009, 04:33 PM   #3
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Yes, exit status won't do it here. A slightly messy indirect way would be to count the number of lines (matches) that find outputs:

if test `find . -name $filename | wc -l` -gt 0; then
   echo yes
   echo no
However, if it's just a simple file existence test that you're after, bash has built-in conditional operators to do this:

if [ -e $filename ]; then
   echo yes
   echo no
There are several such operators (see man bash for more).
Old 11-09-2009, 02:52 AM   #4
LQ Newbie
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: 0


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 04:02 PM
Compiling GIMP: "collect2: ld returned 1 exit status" linx win Debian 1 01-15-2007 12:08 AM
Help with "man pppd" exit status 10 Larry Webb Linux - Networking 1 07-29-2006 02:59 AM
kppp mdk10 ppp exit status 10 "CONNECT 44000/LAPM/" geek745 Linux - Networking 2 09-09-2004 11:04 PM
problem with "rpm -bb" , 1 out of 1 hunk ignored ...error: Bad exit status from /v wohaolouis Linux - Software 0 03-07-2004 07:12 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration