[SOLVED] grep stdout to file and stderr to another file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want output to go to one file and errors to go to another file. This works, however as the command stands right now, it doesn't return to the command line when terminated. thanks.
When terminated or when complete? It seems to work ok for me. Are you sure you want the /* and not ./*?
I did want to search entire root. The command does what it's suppose to do, but it does not seem to terminate as it doesn't return the command prompt back to me without hitting Ctrl-c.
Doing a recursive grep on the ENTIRE filesystem will take a long time...are you sure it isn't still running when you're hitting Ctrl+C? Try running it on a small directory with only a few files and see what happens.
All that, and grepping certain "files" seems to never return. I'd recommend
a slightly different approach. find / -type f | xargs -i grep -n 'this*' /* >output.txt 2>errors.txt
Doing a recursive grep on the ENTIRE filesystem will take a long time...are you sure it isn't still running when you're hitting Ctrl+C? Try running it on a small directory with only a few files and see what happens.
You may be right. Or it may just hang because it's hit a socket or something else that I've been reading about. It runs fine on selected directories as you suggested, so I guess I should just limit my searches.
Thanks for your help. And you too maniannam.
I'll look into using xargs as well.
Last edited by hansfordmc; 08-26-2012 at 04:39 PM.
You may be right. Or it may just hang because it's hit a socket or something else that I've been reading about. It runs fine on selected directories as you suggested, so I guess I should just limit my searches.
Thanks for your help. And you too maniannam.
I'll look into using xargs as well.
The crucial bit there is the -type f switch to find, that will stop
you from grepping character devices, kernel RAM and other funky things from
which grep may not return ;}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.