find . -name "*.*" | xargs grep "help"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find . -name "*.*" | xargs grep "help"
# 1  
Old 06-09-2011
find . -name "*.*" | xargs grep "help"

Hi all,

I am a unix noob. Need some basic help. I have tried using google, but not able to figure this out.

Here are the scenarios:

1. How do I find a directory with a particular name, say "Merlin" in the entire file system? I tried :
Code:
find / -type d -name "dir_name"

The problem is I'm getting thousands of lines, most of them with "blah blah blah...Permission denied".

How can I have only the relevant information, the directory that I am looking for with its path.

2. How do I find a file with name "unicorn", where I do not know it's directory location?
Code:
find . -name "unicorn" -print

.

Same problem, lots of hits with "permission denied".

3. How do I find a file, where I do not know it's location which has a particular pattern inside the file.

This was a bummer. Couldn't find anything. Please help.
# 2  
Old 06-09-2011
Quote:
Originally Posted by neil.k
Hi all,

I am a unix noob. Need some basic help. I have tried using google, but not able to figure this out.

Here are the scenarios:

1. How do I find a directory with a particular name, say "Merlin" in the entire file system? I tried :
Code:
find / -type d -name "dir_name"

The problem is I'm getting thousands of lines, most of them with "blah blah blah...Permission denied".

How can I have only the relevant information, the directory that I am looking for with its path.

2. How do I find a file with name "unicorn", where I do not know it's directory location?
Code:
find . -name "unicorn" -print

.

Same problem, lots of hits with "permission denied".

3. How do I find a file, where I do not know it's location which has a particular pattern inside the file.

This was a bummer. Couldn't find anything. Please help.

1. Correct, you need to be root in order not to have "Permission denied" and search the hole system

2. Same as the first just replace the . with /

3. Find cannot look trough the contents of a file, this can be done with various scripts for example:

Code:
find / -type f | xargs grep "John Smith ID"

This will probaly print thousands of lines if you are not very specific about what you`re searching for, also it will run slow since it have to read every file on your disk. Good advise is at least to remember the directory where the file is.

For more see

Code:
man find
man grep
man locate
man whereis
man which

Filesystem Hierarchy Standard - Wikipedia, the free encyclopedia
# 3  
Old 06-09-2011
redirect STDERR to /dev/null

To get rid of the permission errors with find, redirect its STDERR to /dev/null (the bit bucket when you don't care about the output).
Code:
find / -type d -name "dir_name" 2>/dev/null

# 4  
Old 06-09-2011
Also, "*.*" is a DOS thing. If you want to match everything, don't give find any name or iname at all.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping grep and xargs

In a directory I have two lists, all files which could contain certain fields (they all share copied code) and a list of fields. My two scripts are <appl.list xargs grep $1 where appl.list contains files (source programs) with the fields. This script is named YY <fields.list xargs YY ... (4 Replies)
Discussion started by: wbport
4 Replies

2. Shell Programming and Scripting

Help with find, xargs and awk

Hi, I want to find some files and then search for some lines in it with a particular pattern and then write those lines into a file. To do this I am using something like this from command prompt directly. cd /mdat/BVG find -name "stmt.*cl" -newer temp.txt | xargs -i awk '/BVG-/{print}' {} >... (7 Replies)
Discussion started by: Sandhya Harsh
7 Replies

3. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

4. Shell Programming and Scripting

Find common terms in two text file, xargs, grep

Hello, I'm interested in finding all occurrences of the terms in file1 in file2, which are both csv files. I can do this with a loop but I'm interested in knowing if I can also do it with the help of xargs and grep. What I have tried: cat file1 | xargs grep file2 The problem is that... (15 Replies)
Discussion started by: eon
15 Replies

5. Shell Programming and Scripting

Xargs + Find Help

Guys i want to run a command to list all directories that havn't been modified in over 548 days ( 1.5 yrs ). Id like to run a script to first print what the command finds ( so i get a list of the files pre move ... i have a script set for this : find /Path/Of\ Target/Directory/ -type d -mtime... (4 Replies)
Discussion started by: modulartention
4 Replies

6. Shell Programming and Scripting

File find | xargs grep for pattern file

Folks I've been struggling this with for far too liong now and need your help! I've been happily using grep for a search of a directory, to list the files which contain a string: find . -type f -mtime -5 -print | xargs grep -l 'invoiceID=\"12345\"' Now the list of 'invoiceID' I am... (4 Replies)
Discussion started by: daveaasmith
4 Replies

7. Shell Programming and Scripting

find and xargs

hi, i've been trying to figure this weird error but I cannot seem to know why. I am using below find command: find . \( ! -name . -prune \) -type f -mtime +365 -print The above code returns no file because no files are really more then 365 days old. However, when I use xargs, its... (9 Replies)
Discussion started by: The One
9 Replies

8. UNIX for Dummies Questions & Answers

XARGS and FIND together

I am trying to delete files older than 60 days from a folder: find /myfolder/*.dat -mtime +60 -exec rm {} \; ERROR - argument list too long: find I can't just give the folder name, as there are some files that I don't want to delete. So i need to give with the pattern (*.dat). I can... (3 Replies)
Discussion started by: risshanth
3 Replies

9. UNIX for Dummies Questions & Answers

problem with grep in combination with xargs

Dear all, I have tried the following 2 lines xargs -t -i -exec grep -i -w {} file_1 >>test < file_2 cat -s file_2| xargs -t -i -exec grep -i -w {} file_1 >> test They were meant to search for the contents of file_2 in file_1 and write the respective lines of file_1 into file "test" .... (15 Replies)
Discussion started by: Bruno
15 Replies

10. Shell Programming and Scripting

grep and xargs

guys... I wanna use xargs in such a way that i can use it in grepping the fileds.. something like this: grep -p <xargs values> * lemme know how to do this.. (5 Replies)
Discussion started by: freakygs
5 Replies
Login or Register to Ask a Question