finding multiple files using find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding multiple files using find command
# 1  
Old 11-10-2010
finding multiple files using find command

I am trying to search for 2 files using the find command as below

Code:
find -name file1.txt -a -name file2.txt

It doesn't give a result although the files exist in the folder, however when i try the following

Code:
find -name file1.txt -o -name file2.txt

It does give me the result.

./file2.txt
./file1.txt

I want to search for the existance of these two files. How can I do that please.

Please note there can be 3 cases

1) No file exist
2) One file exist
3) Both file exist
This User Gave Thanks to vivek_damodaran For This Post:
# 2  
Old 11-10-2010
Code:
find . \( -name file1.txt -o -name file2.txt \) -print

This User Gave Thanks to methyl For This Post:
# 3  
Old 11-10-2010
Code:
find -name file1.txt -a -name file2.txt

this will try to find a file with name "file1.txt" AND "file2.txt". No match, so no result.
For your need, may be you can use Logical OR and count the result.
Code:
find . \( -name file1.txt -o -name file2.txt \) | wc -l

If count is zero, no file exists,
If count is one, one file exists,
If count is two, both files exist.
This User Gave Thanks to anurag.singh For This Post:
# 4  
Old 11-11-2010
Thanks guys....that worked
# 5  
Old 11-12-2010
Quote:
Originally Posted by vivek_damodaran
Thanks guys....that worked
Please use the bottom right button of posts to thanks people when their post helped you.
This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

2. Shell Programming and Scripting

Finding older files using find command

Hi All, I want to find files which are older than 15 days. I have written a command as below, find -mtime +15 -print I understand (System date - last modified time of a file) should be greater than or equal to 15 days. This command returns files which are 15 days old.. i.e... (1 Reply)
Discussion started by: nshan
1 Replies

3. UNIX for Dummies Questions & Answers

Finding and Extracting uniq data in multiple files

Hi, I have several files that look like this: File1.txt Data1 Data2 Data20 File2.txt Data1 Data5 Data10 File3.txt Data1 Data2 Data17 File4.txt (6 Replies)
Discussion started by: Fahmida
6 Replies

4. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

5. UNIX for Dummies Questions & Answers

Finding nth line across multiple files

I have several files (around 50) that have the similar format. I need to extract the 5th line from every file and output that into a text file. So far, I have been able to figure out how to do it for a single file: $ awk 'NR==5' text1.txt > results.txt OR $ sed -n '5p' text1.txt > results.txt... (6 Replies)
Discussion started by: oriqin
6 Replies

6. Shell Programming and Scripting

multiple regex finding in files

Hello folks, I have a text file aa.txt that contains below text (\')|(\-\-) ((\%3D)|(=)) 20%0d% i want to search each line pattern in /opt/1.log and /opt/2.log. Can some one suggest (1 Reply)
Discussion started by: learnbash
1 Replies

7. Shell Programming and Scripting

I need to find one command from multiple files and need to print that file which contains neede com

Hi all i need your help .. I am having a multiple file in directory and i have find out the Rcopy word from these files and need to print those files which contains the Rcopy word Thanks and regards Vijay sahu (2 Replies)
Discussion started by: vijays3
2 Replies

8. UNIX for Dummies Questions & Answers

Finding names in multiple files - second attempt

I couldn't find the original thread that I created and since I didn't get a definitive answer, I figured I'd try again. Maybe this time I can describe what I want a little better. I've got two files, each with thousands of names all separated by new line. I want to know if 'name in file1'... (2 Replies)
Discussion started by: Rally_Point
2 Replies

9. UNIX for Dummies Questions & Answers

Finding Names in multiple files

What's the best way to see if a common name exists in two separate files? (3 Replies)
Discussion started by: Rally_Point
3 Replies

10. Shell Programming and Scripting

find - finding files.

I understand that to find a type of file using command find I could do "find -type f -name \*.htm -print". However, I wish to find all files BUT *.htm. Can I negate the search somehow? Again, I have peeked into the man files etc... If anyone has an answer, Thanks in Advance! (3 Replies)
Discussion started by: gsjf
3 Replies
Login or Register to Ask a Question