Find: return code check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find: return code check
# 1  
Old 12-10-2010
Find: return code check

Hi,

I've a find command like,

Code:
 
find /abcd/efgh -name "xxxx" 2> /dev/null > file1

what would be the condition to check if this returns none(means if the file "xxxx" is not present) ????

I tried checking with $? and it returns 72 to me but even the file is present also it returns the same 72.

Any suggestions ?

Thanks,
Vasanth
# 2  
Old 12-10-2010
Would the following suffice?
Code:
#!/bin/ksh
if [ -f xxxx ]
then
   echo "File exists"
else
   echo "File missing"
fi




I hope that this helps.


Robin
Liverpool/Blackburn
UK
# 3  
Old 12-10-2010
Code:
if [ -e "/abcd/efgh/xxxx" ] ; then
   echo "file exist"
else
   echo "file not exist"
fi


  • -e: Returns true value if file exists
  • -f: Return true value if file exists and regular file
R0H0N
# 4  
Old 12-10-2010
Thanks of your reply guys!

But, here I don't know the exact path. So i'm finding under /abcd/efgh instead of checking with if condition. It can be present in any of its sub directories. So now i need to check whether the find command is returning any directory list or not. Any suggestions?

Thanks,
Vasanth.
# 5  
Old 12-10-2010
Code:
if [ ! -z `find /abcd/efgh -name "xxxx" 2>/dev/null` ] ; then
    some files found
else
    no files
fi

This User Gave Thanks to For This Post:
R0H0N
# 6  
Old 12-10-2010
If you run the "find" without redirecting the error channel, what error messages do you get? The error reply will be to do with that problem.

A "find" run should return zero whether or not it found the file. A value other than zero means that "find" encountered a problem during the search.
# 7  
Old 12-10-2010
Rohon,

That works great! Thanks a lot Smilie

Methyl,

I got few
Quote:
access related error
so i redirected them. Anyways now i was able to get the output as expected.

Thanks a lot guys for your reply!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to return from background process and check if it is running or not?

Hi Team, i am executing 3 scripts in background from 1 script and i want to send a message once the script gets completed.these scripts usually takes 1 hr to complete. My sample script is below, Vi abc.sh sh /opt/data/Split_1.sh & sh /opt/data/Split_2.sh & sh /opt/data/Split_3.sh & ... (3 Replies)
Discussion started by: raju2016
3 Replies

2. Shell Programming and Scripting

Check wget return code

hello check this script it jump to else part, in n both cases, (if files exist or not) wget $MIRROR/kkk.zip && wget $MIRROR/jjj.zip RC="$?" if ] then echo -e "$RED Ooops, Download links are broken...! $RESET" else echo -e "$GREEN Everything is fine, Cheers ... $RESET" fi (4 Replies)
Discussion started by: nimafire
4 Replies

3. UNIX for Dummies Questions & Answers

Why my find return not expected?

root@intel_5500_server:~# find / -name bin -o -name sbin /usr/bin /usr/lib64/pm-utils/bin /usr/lib64/rpm/bin /usr/sbin /bin /sbin root@intel_5500_server:~# which ovs-pki /usr/bin/ovs-pki why below command return nothing root@intel_5500_server:~# find /... (8 Replies)
Discussion started by: yanglei_fage
8 Replies

4. Shell Programming and Scripting

*ix script to check port of client server and return output

Hello EveryOne, I am new to *ix. some could help to write a script. Problem :- Have to ssh to so many client and check port or filesystem usage, so thinking to automate using script. What i Need:- when i run script on my Launchpad server, it should Should ask and SSH to user provided... (3 Replies)
Discussion started by: MeFirst
3 Replies

5. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

6. UNIX for Dummies Questions & Answers

Why do these 2 find commands return different results?

Hi, I am using the korn shell on Solaris box. Why does the following 2 commands return different results? This command returns no results (I already used this command to create a list of files which I moved to an archive directory) find ????10??_*.dat -type f -mtime +91 However this... (15 Replies)
Discussion started by: stumpy1
15 Replies

7. Shell Programming and Scripting

check if return value is blank

Hi, i am trying to get the no of users using nofActUsers=$(echo /usr/sbin/lsof -l | grep "/mast/data/users" ) it will return blank, if the user does nto have permissions to run the script. Now I need to check if the valueis blank i have route to another script else the user has to... (1 Reply)
Discussion started by: Satyak
1 Replies

8. Shell Programming and Scripting

Find command return type

Hi all does find command return anything if the file to be searched is not found? Like if I search from a file in a dir does it return false or null if the file is not found? Please suggests. (3 Replies)
Discussion started by: Veenak15
3 Replies

9. UNIX for Dummies Questions & Answers

to check if file is empty or not and return a non zero value

Hi All, I am new to unix worldd . I need to check a file1 if its empty or not. If its empty then return a non zero value say 99 could you pls let me know the perl script for this. (2 Replies)
Discussion started by: mavesum
2 Replies

10. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies
Login or Register to Ask a Question