I am trying to search for 2 files using the find command as below
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
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
methyl
November 10, 2010, 12:35pm
2
find . \( -name file1.txt -o -name file2.txt \) -print
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.
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.
Thanks guys....that worked
ctsgnb
November 12, 2010, 8:57am
5
Please use the bottom right button of posts to thanks people when their post helped you.