Find command not searching recursively


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find command not searching recursively
# 1  
Old 06-10-2013
Find command not searching recursively

I'm searching for particular scripts that contain pattern "BASIS" so I used the following command:

Code:
find . -type f -print | xargs grep "BASIS"

or

Code:
find . -type f -exec grep "BASIS" {} \;

However, I found out that the find command in the UNIX box that I'm working on doesn't find files recursively. For example

directory A contains directory B, directory B contains directory C, then directory C contains the scripts 1.sh, 2.sh, and 3.sh e.g.

Code:
/A/B/C/ > ls
1.sh              2.sh             3.sh

When I try to execute the commands above on /A, I don't get any results. I cd on B folder and execute the commands above and I get results. e.g.

Code:
/A > find . -type f
/A > 
/A > cd B
/A/B > find . -type f
./C/1.sh
./C/2.sh
./C/3.sh

What could be the problem with find command? How can I make the find command search recursively on all directories under this folder? I'm on a HP-UX server if that helps.
# 2  
Old 06-10-2013
First of all check if these are symbolic links.

By default find command does not follow if it is a symbolic link.

You have to use -follow option which causes find to follow symbolic links:
Code:
find . -type f -follow

This User Gave Thanks to Yoda For This Post:
# 3  
Old 06-10-2013
Quote:
Originally Posted by Yoda
First of all check if these are symbolic links.

By default find command does not follow if it is a symbolic link.

You have to use -follow option which causes find to follow symbolic links:
Code:
find . -type f -follow

That use of -follow has no effect whatsoever since no symbolic link occurs after it. Not all find implementations support -follow, and it's deprecated for those that do.

If you are correct and the issue is that a symbolic link is not being followed, the simpler and portable solution is to use -L.

Regards,
Alister

---------- Post updated at 03:56 PM ---------- Previous update was at 03:54 PM ----------

To the OP, it might help to see the output of ls -alR from the parent of A.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 4  
Old 06-10-2013
Alister, using that command I found out that some directories are actually symbolic links and the use of -follow seems to be working for me so far.

Thanks a lot guys.
# 5  
Old 06-10-2013
@The Gamemaster:
Woops. I misunderstood how -follow works. Still, probably better to use -L.

@Yoda:
Nice catch.

Regards,
Alister

---------- Post updated at 04:39 PM ---------- Previous update was at 04:24 PM ----------

From Symbolic Links - Finding Files
Quote:
‘-follow'

This option forms part of the “expression” and must be specified after the file names, but it is otherwise equivalent to ‘-L'. The ‘-follow' option affects only those tests which appear after it on the command line. This option is deprecated. Where possible, you should use ‘-L' instead.
If the it is otherwise equivalent to `-L' clause is true (which, as far as I can tell it is), then why is it followed by further qualifications.

If The ‘-follow' option affects only those tests which appear after it on the command line. were true, then a -follow at the end of a command would have no effect. If this were correct, then Yoda's -follow would have no effect since it occurs at the end of a command line, with nothing to affect after it.

I just ran a few tests and confirmed that Yoda's find does indeed work. In my opinion, that success contradicts the GNU find manual.

This is not something that troubles me deeply, since I don't depend on a GNU userland; I just thought it might be worth pointing out.

Regards,
Alister
# 6  
Old 06-10-2013
Quote:
Originally Posted by alister
@The Gamemaster:
Woops. I misunderstood how -follow works. Still, probably better to use -L.

@Yoda:
Nice catch.

Regards,
Alister

---------- Post updated at 04:39 PM ---------- Previous update was at 04:24 PM ----------

From Symbolic Links - Finding Files

If the it is otherwise equivalent to `-L' clause is true (which, as far as I can tell it is), then why is it followed by further qualifications.

If The ‘-follow' option affects only those tests which appear after it on the command line. were true, then a -follow at the end of a command would have no effect. If this were correct, then Yoda's -follow would have no effect since it occurs at the end of a command line, with nothing to affect after it.

I just ran a few tests and confirmed that Yoda's find does indeed work. In my opinion, that success contradicts the GNU find manual.

This is not something that troubles me deeply, since I don't depend on a GNU userland; I just thought it might be worth pointing out.

Regards,
Alister
How do you use the -L option? Like find -L . -type f? Or find . -type f -L? It doesn't work for me either way. Yoda's suggestion works for me so far.
# 7  
Old 06-10-2013
The proper solution is to ignore me.

I was quoting the GNU find manual above and had not realized that you were on HP-UX.

I am not familiar with HP-UX, but a manual page that I found online indicates support for -follow and no support for -L (which I believe was added to POSIX in the 2004 edition).

Further, the HP-UX manual does not seem to contradict itself. From find - HP-UX :
Quote:

-follow

A position-independent term which causes find
to follow symbolic links. When following
symbolic links, find keeps track of the
directories visited so that it can detect
infinite loops; for example, such a loop would
occur if a symbolic link pointed to an
ancestor. This expression should not be used
with the -type l expression. Always true.
I apologize for creating confusion. Revel in your -follow glory.

Regards,
Alister
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find file type recursively and move

Hello, I supposed that it was working fine but now I see that it's not working as expected. I am running under ubuntu14.04, trusty. My plan was to search folderA and all subdirectories and move any txt file to destination folder, folderB : find /home/user/folderA/ -type f -iname "*.txt"... (0 Replies)
Discussion started by: baris35
0 Replies

2. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

3. UNIX for Dummies Questions & Answers

Find and rename file recursively

Hi, I have a directory which contains multiple files with .txt extension, i want to rename all these file to .bak extension using find command, this is what i've tried, please help me to correct this : find /home/application/test -name '*.txt' -exec rename 's/txt/bak/' {} \; seems to... (8 Replies)
Discussion started by: mukulverma2408
8 Replies

4. Shell Programming and Scripting

How to find and replace a string with spaces and / recursively?

Hi all, I wanted to find and replace an email id from entire directory structure on a Linux server. I found that find . -type f -print0 | xargs -0 sed -i 's/abc@yahoo.com/xyz@gmail.com/g' would do it perfectly. But my search criteria has extended and now I want to search for a string1 like... (2 Replies)
Discussion started by: pat_pramod
2 Replies

5. UNIX for Dummies Questions & Answers

Find and cat top lines recursively

I have a folder structure with multiple sub directories MAIN FOLDER1 SUBFOLDER1 files...... FOLDER2 SUBFOLDER1 files...... etc and I want to find a way to create an output of every files first 20 lines. I've been searching and testing and failing. I can do it in a... (2 Replies)
Discussion started by: darbs121
2 Replies

6. Shell Programming and Scripting

find command not searching path when -newer specified

When this command is issued from a directory other than where the file is located it works fine: find /db2/D01/log_archive/ -name "S0002166.LOG" -type f /db2/D01/log_archive/db2d01/D01/NODE0000/C0000000/S0002166.LOG When I change -name to -newer, it doesn't work. Find only searches the current... (5 Replies)
Discussion started by: fletchdb2
5 Replies

7. Shell Programming and Scripting

Recursively *.ext files using find

HI, Getting the syntax error " find: missing conjunction" for the below code D1_DIR=/x/y/z D1_NAME=file_name FILE_DIR=pset for file in `find ${D1_DIR}/${D1_NAME} -name "*\.${FILE_DIR}" /dev/null {} \;` do echo $file done #Trying to find all the files with *.pset... (5 Replies)
Discussion started by: cvsanthosh
5 Replies

8. Ubuntu

How to find symbolic links recursively under a folder in Linux

Hi , I have folder which has almost 35000 objects, I need to find out or list the objects which are symbolic links. I tried f. I am not getting right Can you pls help Regards amv (5 Replies)
Discussion started by: amvarma77
5 Replies

9. Shell Programming and Scripting

how to get only filename in a recursively find command

Hi i would like to ask on how to accomplish the FF: I want to execute a find command recursively and only get the filename something like i want only the last field set if is used ever the fieldvset as an redirection from the output of the find command For example: dir1/dir2/filename1... (2 Replies)
Discussion started by: jao_madn
2 Replies

10. Shell Programming and Scripting

Find the number of non-duplicate names recursively.

Hi, here comes another newbie question: How to find the number of non-duplicate names recursively? For example, my files are stored in the folders like: If I do find . -depth -name "*.txt" | wc -l This will gives out a result "4". One .txt file named "1.txt" in folder "1", and... (2 Replies)
Discussion started by: jiapei100
2 Replies
Login or Register to Ask a Question