How to find a specific files in a many directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find a specific files in a many directory
# 1  
Old 05-28-2008
How to find a specific files in a many directory

Dear All,

Appreciate some help here.

I have a log of report. It located in several directory as below:

Directory:
mysscpr1
mysscpr2
mysscpr3
my_scnpr4

In the directory it contain hundred of files.

i need to find a specific files that contain 'invc2345' in the directory.

How can i do that? without need to 'cd <directory name> ' and then use the grep command one by one in every directory such as

cd <directoryname>

grep invc2345 *

Please assist
# 2  
Old 05-28-2008
Use the find and grep command together.That should solve the purpose..

Code:
find . -name mysscp l -exec grep invc {} \;

# 3  
Old 05-28-2008
Dear nua,

May be my explaination is not clear:

This is the sample of directory:

drwxrwxr-x 3 xxxxx ulol 368640 May 28 14:24 mycrdpr1
drwxrwxr-x 3 xxxxx ulol 96 Oct 19 2007 mycrdpr2
drwxrwxr-x 3 xxxxx ulol 96 Oct 1 2007 mycrdpr3
drwxrwxr-x 3 xxxxx ulol 96 May 23 08:15 myfinpr2
drwxrwxr-x 3 xxxxx ulol 8192 Mar 1 08:26 myfinprn
drwxrwx--- 2 xxxxx ulol 96 Jul 26 2007 mynpprn1
drwxrwxr-x 3 xxxxx ulol 16384 May 26 12:56 mypngpr1
drwxrwxr-x 3 xxxxx ulol 1064960 May 28 14:26 mysscpr2
drwxrwx--- 2 xxxxx ulol 96 May 15 06:00 sgisbprn1

I'm looking for an invoice number JHK8888 where it located in one of the directory and in a file under the directory.

Below is the sample of file under the directory:

-rw-r----- 1 1253 ulol 5386 Jul 6 2007 IBCRNtKL.abor.212113
-rw-r----- 1 1253 ulol 200070 Jul 9 2007 IBCRNtKL.abor.212941
-rw-r----- 1 chaiyeel ulol 5270 Jul 30 2007 IBCRNtKL.chel.2220
50

The problem is i also dunt know where is the file located and under which directory. I dont want to cd directory one by one and user grep to look for the invoice number. I want to make it easy.

Please advice.

Rgrds

Shahril
# 4  
Old 05-28-2008
grep -R "<Search String>" *
# 5  
Old 05-28-2008
Dear siba,

Please find error below:

$ grep -R JHBI11117 *
grep: illegal option -- R
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]
$
# 6  
Old 05-28-2008
Have u checked the man page for grep command?
If -R is not working then u can use -r here and try it.



Quote:
Originally Posted by selamba_warrior
Dear siba,

Please find error below:

$ grep -R JHBI11117 *
grep: illegal option -- R
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]
$
# 7  
Old 05-28-2008
Code:
find /path/to/find -type f -name "pattern_of_file" -o -name "pattern_of_file" | xargs grep -i "pattern_to_find"

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Large Files Recursively From Specific Directory

Hi. I found many scripts in the web of achieving this. But I like to use this one find /EDWH-DMT03 -xdev -size +10000 -exec ls -la {} \;|sort -n -k 5 > LARGE.rst But the problem is, why it still list out files with 89 bytes as the output? Is there anything wrong with the command? My... (7 Replies)
Discussion started by: aimy
7 Replies

2. UNIX for Dummies Questions & Answers

How to search in specific directory using find?

Hi, Is there any way to use find command and search only specific subdirectories in a directory. for example /home/d1 /home/d2 /home/d3 i want to search in the following directories /home /home/d1 /home/d2 i do not want the find command to search the /home/d3 directory. (6 Replies)
Discussion started by: Little
6 Replies

3. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

4. Shell Programming and Scripting

How to copy a directory without specific files?

Hi I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.). Pls advise how can I do that. Thanks (17 Replies)
Discussion started by: reddyr
17 Replies

5. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

6. Shell Programming and Scripting

Find all the files under a specific directory and zip them into a single file.

Hi, Is there a way to find all the files from a specific location and then zip them into a single file, even if they are in multiple directories? (3 Replies)
Discussion started by: rudoraj
3 Replies

7. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

8. UNIX for Dummies Questions & Answers

Splitting files into a specific directory

Hello, I am trying to do the following; bzcat data.in.bz2 | split -l 1000000 -d this work great, except that once the files have been split, they are not in the directory I want them to be in. So I then have to move them, at times this can get hairy. Is there anyway to specify where the... (4 Replies)
Discussion started by: amcrisan
4 Replies

9. Solaris

List all files that contain a specific directory

I need to list all files and subdirectories that contain "oradata". For example, I have several files in several different directories that contain "oradata". I.e. /u07/oradata/1.dbf /u09/unix/whatever/oradata/2.xxx That is, whatever file on the system that contains a directory called... (7 Replies)
Discussion started by: Sat510
7 Replies

10. Shell Programming and Scripting

delete files in specific directory

i have a directory "ABC" with lots of old files and sub directories in it. the issue now is i want to delete away files which are older than 15 days in "ABC" without deleting the files in the sub directories and without deleting the sub directory. i tried using find command but it will drill down... (2 Replies)
Discussion started by: legato
2 Replies
Login or Register to Ask a Question