Find command return type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find command return type
# 1  
Old 07-15-2009
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.
# 2  
Old 07-15-2009
Posix-sh, ksh, bash, ...

look value of variable ? after commandline
echo $?
0=ok
<>0 not ok
# 3  
Old 07-15-2009
You can combine the "find" command with the "wc -l" so that the result will > 0 if some files found and return 0 if file not found.
Code:
find ./ -name "something" | wc -l

Hope this help.

Last edited by thanhdat; 07-16-2009 at 05:05 AM..
# 4  
Old 07-16-2009
I have tired something like this, but it doesn't seem to work ==>

F2=$(find "${directory2}" -name "$F")
rc=$?
if [ ${rc} -ne 0 ]
then
print "WARNING: Could not locate file : $F in $directory2"
fi

---------- Post updated at 01:32 PM ---------- Previous update was at 11:03 AM ----------

The following worked!!
Thanks to all for the valueable replies
F2=$(find "$directory2" -name "$F")
echo "$F2 : $F"
if [ "$F2" = "" ]
then
print "No such $F file found"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trapping the return status from FIND command

I have the following code in a script: find . \( ! -name . -prune \) -name "cg*" -exec cp -p {} "${temp_dir}" \; ret_stat=$? I think the return status is only captured for the 'find' command and not for the 'cp' command. Is there a way to get the return status for the 'cp' command... (7 Replies)
Discussion started by: vskr72
7 Replies

2. HP-UX

Find command doesn't return in shell script.

Hi All, I am using below snippet to search for a string (read from a file 'searchstring.out') in all locations (/) and then iterate over the files found to write the locations and the respective owner to an output file. However, this doesn't work as I believe the find command doesn't exit's... (11 Replies)
Discussion started by: Vipin Batra
11 Replies

3. Programming

Struct as return type

Hello all, I am trying to define a function with return type as struct, but seem to be failing. Error I am receiving is following .CC error: prototype for 'RpcHOData L1ITMu::MBLTCollection::getUnassociatedHORpcClusters(double)' does not match any in class 'L1ITMu::MBLTCollection' struct... (1 Reply)
Discussion started by: emily
1 Replies

4. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

5. Shell Programming and Scripting

what is the default return type of localtime() in perl?

Hi, I have given like this to get the time of the sub routine. my $start = localtime(); print "\n start time: $start \n"; Output start time: Fri Apr 29 01:01:31 2011 I want to know what is the format of the time. I am not able to follow is is HH:MM:SS or MM:HH:SS os... (2 Replies)
Discussion started by: vanitham
2 Replies

6. UNIX for Advanced & Expert Users

Command to find the "unix machine type".

Hi all, Just need some help the following scenario, Is there any UNIX command to find the unix machine type (like whether the machine is belongs to Ssun ultra 45 type) like that .. please help me (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

7. 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

8. Programming

Help - Cast converts default int return type

What does the warning message 724 "Cast converts default int return type to." tell me. I am new to C. (used it some in college). We are migrating our c-code to 10.2.0.3.0. The programs compiled clean. However there were several warning messages that kick out. The most prominent warning is: ... (5 Replies)
Discussion started by: rtgreen
5 Replies

9. UNIX for Dummies Questions & Answers

find . -type d -exec cd {} \;

Hi all Can anyone tell me why this is not working ? i saw somewhere that i must have serach (execute) permission which i have but it still wont work thx (2 Replies)
Discussion started by: shimont
2 Replies
Login or Register to Ask a Question