How to redirect a input of find command into a text file

Hello friends,

I want a command to print the reult files from find command into a text file.:slight_smile:
Iam looking from forum memebers. PLZ help me.ASAP

Thanks in Advance,
Siva Ranganath CH

You already use the correct term "redirection". So putting this together with "shell" and issue a search in Google, you get plenty hits for this very very basic question.

As a reminder:

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums

1 Like

What do you mean by "print" ?

find dir -type f -print | lpr -p<printer>

Or do you mean you want to keep the output of the find in a text file ?

find dir -type f -print > myfile.txt

My qusetion is to print in the text file.
for example.
I have command below
find .-type f -exec grep -l "string" {} \; i want to print the output of command into a text file with in the same path.:slight_smile:
so can i write the like this
find .-type f -exec grep -l "string" {} \ > myfile.txt.

Thanks for your reply.
Siva Ranganath CH.

You were 99% there. Assuming you are trying to find all files containing "string". Note the space character either side of "." the escaped semi-colon and the "." removed at the end of the target filename.

find . -type f -exec grep -l "string" {} \; > myfile.txt

As an aside, your example will give a list of files that contain "strings".
Sometimes you want the whole grep line and the filename:

find . -type f -exec grep "string" {} /dev/null \; > myfile.txt

Cheers