Problem with files returned using Find command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem with files returned using Find command
# 1  
Old 11-22-2006
Problem with files returned using Find command

When I enter the command below grep appears to be returning a file it shouldn't.

find . -name "*.*" -exec grep "testing" {} /dev/null \;
:tps3Mailfile
./SSI.ksh: # create TECHOUT dummy for test for testing purposes
./ftprimi1.ksh:# before running job in prod... change FTP to go to rimi instead of rad box(testing)
./pharm_alert.ksh:# send mail for testing, but not in prod

The file, tps3Mailfile does not contain the search string testing, why does this command continually pull this file? If I rerun the above using -type option instead of -name for the find command then the proper files are returned. Also, if you look at the path returned for this file it lists :tps3MailFile instead of ./tps3MailFile as one would expect.

Anyone have any ideas why this file is returned? If you use grep on this directory without the find command then the proper list of files is returned.

Thanks

D
# 2  
Old 11-23-2006
Quote:
Originally Posted by dfb500
If you use grep on this directory without the find command then the proper list of files is returned.
A directory is a file which contains entries and each entry is a filename and an inode number. I doubt that you really mean to run grep on a directory. Instead you mean to run grep on the files in a directory. These are two very different concepts. But your find statement is doing both of them. The current directory is . and it will match *.* and grep will open it and process it. Your output is odd, but directories are not ascii files. Try these commands:

grep testing .
grep testing . | od -c

and maybe you can get a handle on what exactly is happening.
# 3  
Old 12-10-2006
try this..

-exec is pretty inefficient.. use xargs. Try something like:

find . -type f | xargs grep "string"
# 4  
Old 12-12-2006
Yes ... make sure that grep is executed only on plain text files. So I would suggest

find /dirname -name 'blah' -type f -exec grep {} \;
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What is returned when using 'find . -ls'

Hi all, I tried to find the reply using google, yet did not find a conclusive answer. When I use 'find . -ls', I get something like: 3423297 8 -rw-r--r-- 1 useradmin staff 135 4 apr 09:46 ./.~lock.dir-file-list.csv# I know that 3423297 is the inode -rw-r--r-- ... (2 Replies)
Discussion started by: dakke
2 Replies

2. UNIX for Dummies Questions & Answers

sort file returned by FIND command in ascending

Hi there I have to enhance my current file looping to ensure the oldest file being processed first. current command: for FILENAME in `find $MY_DIRECTORY -follow -type f` I manage to get command for order by date modified descending, just can't get the ascending order. Please help for... (3 Replies)
Discussion started by: elsie512
3 Replies

3. UNIX for Dummies Questions & Answers

Delete files returned by ls

I need to delete the files that are returned by this ls command: root@16:06:37@whci03:/var/log/whci# ls -ltrhS | grep "Apr " -rw-r--r-- 1 whci users 180M Apr 4 00:00 20090403_whci_Access.txt -rw-r--r-- 1 whci users 185M Apr 4 00:00 20090403_whci_Access.txt -rw-r--r-- 1 whci users 189M... (3 Replies)
Discussion started by: whci98
3 Replies

4. UNIX for Dummies Questions & Answers

Delete files returned by ls

I need to delete the files that are returned by this ls command: root@16:06:37@whci03:/var/log/whci# ls -ltrhS | grep "Apr " -rw-r--r-- 1 whci users 180M Apr 4 00:00 20090403_whci_Access.txt -rw-r--r-- 1 whci users 185M Apr 4 00:00 20090403_whci_Access.txt -rw-r--r-- 1 whci users 189M... (1 Reply)
Discussion started by: whci98
1 Replies

5. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

6. Shell Programming and Scripting

How to find out command has returned any value?

Hi Pals I am using this command in my script to find out warnings using fgrep where $log is the log file name, $date is the date to be searching and warnings.list contains list of matching words. grep "WARNING" $log|grep "$date"|fgrep -vf warnings.list I want to perform another action... (1 Reply)
Discussion started by: johnl
1 Replies

7. HP-UX

returned from remote command

Hi, there, I want to excute the remote command shell via "remsh", are there any simple or best way to get the result of remote shell from local ? thanks. (2 Replies)
Discussion started by: Frank2004
2 Replies

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

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. UNIX for Advanced & Expert Users

w/who command returned zero users

Hi ppl, We are using Sun OS and recently, encountered this strange problem. When issuing the "w" or "who" command, the system produce no listing. See screen shot below. ----------------------- $ w 2:56pm up 2 day(s), 21:10, 0 users, load average: 1.03, 0.75, 0.69 User tty ... (6 Replies)
Discussion started by: sinyem
6 Replies
Login or Register to Ask a Question