Algorithm of find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Algorithm of find command
# 1  
Old 09-16-2009
Algorithm of find command

Hi folks

I'm new here in this forum and hope to find someone who can help me.

I couldn't find a solution already posted in the forum.

Does anyone know what algorithm the shell command find uses? It looks like Top-Down but I need to be 100% sure. So can anyone confirm that?

Thx for your help
# 2  
Old 09-16-2009
I would say it is top-down, depth first, (i.e. not breadth first). If you do a simple find without options, then once it encounters a directory it starts to explore it and if it encounters a subdirectory there, it will do that one first etc... until it reaches the bottom and then it will go sideways and up again..

e.g.:

Code:
find . -print|more
.
./.bash_logout
./.bash_profile
./.bashrc
./.gconf
./.gconf/desktop
./.gconf/desktop/gnome
./.gconf/desktop/gnome/accessibility
./.gconf/desktop/gnome/accessibility/keyboard
./.gconf/desktop/gnome/accessibility/keyboard/%gconf.xml
./.gconf/desktop/gnome/accessibility/%gconf.xml
./.gconf/desktop/gnome/%gconf.xml
./.gconf/desktop/gnome/font_rendering
./.gconf/desktop/gnome/font_rendering/%gconf.xml

etc..

# 3  
Old 09-16-2009
find uses ftw() or more likely ntfw(). Read the man page on those functions.
# 4  
Old 09-16-2009
Unix "find" does work broadly as described (by Scrutinizer) above but does not sort the input or output.
It's not even in inode number order.

Code:
Try this on a mature tree:

find . -exec ls -id '{}' \;

The stategy is altered by "-depth" parameter:

find . -depth -exec ls -id '{}' \;


Last edited by methyl; 09-16-2009 at 12:23 PM.. Reason: qualified "above".
# 5  
Old 09-22-2009
Thank you for your answers. I'm going to read the man pages and write my report.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

2. Shell Programming and Scripting

An algorithm to be written in linux command

Hi All, I wrote the following script in R. However, i can not run it. Because the data file is so big. Therefore, i need to write it in shell script. Could you please help me? ###################################### data=as.matrix(read.table("data.txt"))... (3 Replies)
Discussion started by: senayasma
3 Replies

3. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

4. Shell Programming and Scripting

Find, regular expression, anyway to simplify this find command?

Hello everyone, first post here, trying to learn scripting on my own and this forum as been really helpful so far. I made few little scripts working great but I m facing some problems with RE. I have a bunch of files in many subdirectories called *001.ext *002.ext OR simple *.ext or *01.ext... (7 Replies)
Discussion started by: Sekullos
7 Replies

5. Shell Programming and Scripting

what is the find to command to find the files created last 30 days

what is the find to command to find the files created last 30 days (5 Replies)
Discussion started by: rajkumar_g
5 Replies

6. Shell Programming and Scripting

what is the find command to find exact dir from the root

I want to find a dir called STOP from the root.so what is the find command. Thanks & Regards Rajkumar (1 Reply)
Discussion started by: rajkumar_g
1 Replies

7. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

9. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question