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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Little bit weired : Find files in UNIX w/o using find or where command
# 1  
Old 05-26-2007
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
# 2  
Old 05-26-2007
Quote:
Originally Posted by jatin.jain
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
the only reason i guess you can't use find is you might be doing homework. but nevertheless .. if you can't use find, use locate? the other way is to use ls with -R option.

Last edited by ghostdog74; 05-26-2007 at 06:00 AM..
# 3  
Old 05-26-2007
Hi Ghost,
i tried using ls but how to do it recursively ls -r ?. It dint work for me
i will show u a snippet of my script

#!/bin/sh
echo $1 #display the input entered
c=$1
ls -l $c | awk `(if(NR>0) pwd)` # usinf ls command and awk i m trying to get those records and print its path,pwd is not working there
# 4  
Old 05-26-2007
assuming you know the file name
Code:
#!/bin/sh
ls -lR / | awk -v filename="$1" '/^\//{ dir=$0} 
                /^-/{ if ( $9 == filename ) { 
		       print "Found " filename " in "dir
		      }
		
		}'


Last edited by ghostdog74; 05-26-2007 at 06:28 AM..
# 5  
Old 05-26-2007
awk: syntax error near line 1
awk: bailing out near line 1
whts this
# 6  
Old 05-26-2007
what did you do? show your code.
# 7  
Old 05-27-2007
#!/bin/sh
ls -lR / | awk -v filename="$1"
'/\//{ dir=$0}
/^-/{ if ( $9 == filename ) {
print "Found : " filename " in " dir
}
}'

I think its the same as u had posted.
Let me know if here is some syntax mistake
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

Command to find 32/64 bit in Linux

Hi, Can somebody tell me which command will help me find whether the OS is 32 bit or 64 bit. OS is LInux Thanks (3 Replies)
Discussion started by: aish11
3 Replies

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

4. UNIX for Dummies Questions & Answers

find files with SUID bit turned on

I'm writing a script that will search for files with the SUID bit turned on, and put the list in a file called id.txt i read that files with the SUID bit turned on are chmod'd to 4000, so i tried: find / -perm 4000 > id.txt also various others such as -perm 4777 etc etc but it found nothing... (1 Reply)
Discussion started by: SoVi3t
1 Replies

5. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

6. Shell Programming and Scripting

How to find sticky bit dir/files

I need to find all sticky bit dir/files on my system and clean them up if necessary. How to I write a script to do this? Thanks. (2 Replies)
Discussion started by: pdtak
2 Replies

7. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies

8. UNIX for Dummies Questions & Answers

Command to find 32/64 bit in Linux

Hi, Can somebody tell me which command will help me find whether the OS is 32 bit or 64 bit. Regards, Giridhara Babu Tadikonda. (3 Replies)
Discussion started by: giribt
3 Replies

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

10. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question