Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using

if [-f $file];then
echo "exists"
echo " `cat $file` "
else
echo "invalid file"
fi.

and i can find out using :
find / -name "filename" . But it i have wanted to search in all directories. How to get this???

Please suggest.

I often use a filename called file1 when testing things. So, it ends up in many of my subdirectories.

[ ~/tmp ] > find . -name file1
./file_lookup/file1
./sort_stuff/file1
./sort_stuff/moved/file1
./verify_format/file1
./edit_text/file1
./text_manip/file1
./sep2files/file1
./unique/file1
./repl_list/file1
./header_ins/file1
./fixed_data/file1
./join_lines/file1
./add_files/file1
./math/file1
./3rec_types/file1
./copy_archive/file1
./concat_files/file1
./extract_data/file1
./remove_lines/file1
./co_loop/file1
./complex_select/file1
./combine_common/file1
./awk_do_something_next/file1

If you want to search your entire system, try the following:

> find / -name file1 2>/dev/null

The 2>/dev/null is to redirect all the possible errors from the system telling you that you do not have rights to read certain directories. This just makes the output 'cleaner' to read. And, go grab a cup of coffee as this search may take a few minutes, or more.

Hi,

Will you please help me if i want the file having extension .txt will come in the format below and stored in a particular file

Example:

Path:/ap06/cfc/hyperion

-rw-rw---- 1 cfahyp cfghyp 7263 Jan 21 20:17 k1.txt
-rw-rw---- 1 cfahyp cffhyp 7263 Jan 21 20:17 k2.txt
-rw-rw---- 1 cfdhyp cfchyp 7263 Jan 21 20:17 k3.txt

Can you help me out.

I have given

find . -name "*.txt" | cat >> k1.txt --------- command

i gives the files in k1.txt file.

Please help.Thanks in Advance.

-- Kaash

dear kaash,

We appreciate your presentation of the question . but we expect more details of your requirement .

BTW find will search any type of file , irrespective of it's extension , by adding key word -type f , if want more particular result then add key word -name (as you did).

Please write the question from the reader's prospective , simple and understandable , as he has to understand the problem from the writer's prospective and will try to provide you the solution(faster/delay) based on your query.