| UNIX/Linux Forum Archives · Rules and Guidelines · Disclaimer |
Help
Search
Members
Calendar
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
![]() ![]() ![]() |
| SQ4LIFE |
Posted: Nov 4 2003, 12:26 AM
|
|
Newbie ![]() Group: Members Posts: 3 Member No.: 129 Joined: 4-November 03 |
Writing "find" code
I've got a project that writing "find" code in solaris. That is finding a file in current and sub directories. While I am looking for some example on the book for two days, but I have no idea where to start. I think I need to use recursion, but is it true? I am still a Unix beginner and the teacher and book didn't give me enough info... Please tell me the way of structure and concept. Thanks in advance. SQ |
| fishsponge |
Posted: Nov 4 2003, 12:38 AM
|
||
|
Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 679 Member No.: 1 Joined: 13-February 03 |
NOTE: I have moved this topic into the Programming forum, as it is not suited to the General forum at all... please read the forum rules, and think before you post :D While it is a *lot* to ask someone else to write the code for you, i think i can try to give you an idea of the general structure... I'm going to assume you want to be able to search for a file called "fred", for example. 1. List contents of current directory. 2. Search (grep?) results for string "fred". 3. If not present, then list contents of first directory. 4. Search results for string "fred". 5. if not present, then list contents of first directory within this directory. 6. keep looping... recursion would probably be a good thing to use. You could then call your find() method on the first directory, and then call it again on the next directory, and the next, and the next etc... If you are really adventurous, you could try looking for the source code for the linux "find" command... to find files in linux named fred, you would use the following command:
so you would need to look through the source code for the bit that gets executed when the "-name" parameter is supplied. HTH. |
||
| SQ4LIFE |
Posted: Nov 4 2003, 04:06 AM
|
|
Newbie ![]() Group: Members Posts: 3 Member No.: 129 Joined: 4-November 03 |
Sorry about breaking the forum rule. I will try look at next time.
Anyway, how can I find the source code for the reference? I've been looking around for a while, but never found. Is it a secret or something? Sorry about dumb questions... And thanks for your help. |
| fishsponge |
Posted: Nov 4 2003, 10:03 AM
|
|
Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 679 Member No.: 1 Joined: 13-February 03 |
s'ok... :D
1. go here: http://www.gnu.org/prep/ftp.html 2. Select a mirror near you 3. go into "findutils" directory 4. download "findutils-4.1.tar.gz" 5. gunzip and untar it into a directory on your machine 6. When it's unpacked, go to the "findutils-4.1/find/" directory, and you will find the C source code for the find command. PLEASE NOTE: This software is released under the GNU Public License (GPL), so please be careful with what you do with it. To find out about the GPL, click here: http://www.gnu.org/copyleft/gpl.html |
| SQ4LIFE |
Posted: Nov 4 2003, 11:10 AM
|
|
Newbie ![]() Group: Members Posts: 3 Member No.: 129 Joined: 4-November 03 |
Thanks for the info. I will be careful about it.
|
| xplicit^ |
Posted: Dec 8 2003, 04:41 PM
|
||
|
Newbie ![]() Group: Members Posts: 2 Member No.: 153 Joined: 8-December 03 |
I assume it works very similar to the command 'dir' (has the same function as ls) in unix, although I used to use 'ls' for unix and 'dir' for MS-Dos. and here the Code for 'dir' .. maybe it can help you:
I hope it could help you a bit. It's just to get your inspiration working :) Actually many scripts like that have a similar basic principle. Cheers, xplicit^ |
||
| fishsponge |
Posted: Dec 8 2003, 06:35 PM
|
|
Administrator ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 679 Member No.: 1 Joined: 13-February 03 |
i think you are slightly confused i'm afraid...
the 'dir' command is *only* for DOS, and simply lists the contents of the current working directory. Using 'dir' with the '/s' option does allow searching, although the code sample you pasted doesn't contain this. The 'cd' command is used in both unix *and* DOS, and serves pretty much the same purpose in both. It will change the current directory that you are working in. The 'cd' command will in no way whatsoever give you a directory listing, or allow you to search. |
| xplicit^ |
Posted: Dec 8 2003, 06:53 PM
|
|
Newbie ![]() Group: Members Posts: 2 Member No.: 153 Joined: 8-December 03 |
i have already edited my post. Sorry mate, it must be my fever. I meant 'ls -la' :)
it doesn't allow searching, of course: but it does look for files in a dir. I think to find something his script/programm should look for files and choose :) |
| nrutter |
Posted: Dec 18 2004, 08:58 AM
|
|
Newbie ![]() Group: Members Posts: 7 Member No.: 721 Joined: 17-December 04 |
The examples section here
may help |
![]() |
![]() ![]() ![]() |